Compare commits

3 Commits

Author SHA1 Message Date
zher52
a3e18fbbf5 调整依赖 更换日志组件 2023-02-26 20:25:03 +08:00
8d98be2ad4 调整依赖 升级日志组件 2022-11-14 14:10:55 +08:00
bfe194ff96 调整项目结构使其符合maven项目
调整javadoc
2022-11-14 13:13:25 +08:00
129 changed files with 1226 additions and 1945 deletions

View File

@@ -21,12 +21,12 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>

View File

@@ -22,7 +22,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>

View File

@@ -6,28 +6,52 @@
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.kohsuke.jinterop</groupId>
<artifactId>j-interop</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.openscada.opc.dcom</groupId>
<artifactId>org.openscada.opc.dcom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.openscada.utgard</groupId>
<artifactId>org.openscada.opc.lib</artifactId>
<version>1.1.0.v20130529</version>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 使用maven-jar-plugin和maven-dependency-plugin插件打包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.freud.opc.utgard.cases.OPCTest2</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,68 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.openscada.opc.dcom.da.OPCSERVERSTATUS;
import org.openscada.opc.dcom.da.impl.OPCServer;
/**
* 获取Server的Status信息 中文
*
* @author Freud
*
*/
public class DCOMTest1 {
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
dumpServerStatus(server);
}
public static void dumpServerStatus(final OPCServer server)
throws JIException {
final OPCSERVERSTATUS status = server.getStatus();
System.out.println("===== SERVER STATUS ======");
System.out.println("State: " + status.getServerState().toString());
System.out.println("Vendor: " + status.getVendorInfo());
System.out.println(String.format("Version: %d.%d.%d",
status.getMajorVersion(), status.getMinorVersion(),
status.getBuildNumber()));
System.out.println("Groups: " + status.getGroupCount());
System.out.println("Bandwidth: " + status.getBandWidth());
System.out.println(String.format("Start Time: %tc", status
.getStartTime().asCalendar()));
System.out.println(String.format("Current Time: %tc", status
.getCurrentTime().asCalendar()));
System.out.println(String.format("Last Update Time: %tc", status
.getLastUpdateTime().asCalendar()));
System.out.println("===== SERVER STATUS ======");
}
}

View File

@@ -1,128 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import java.net.UnknownHostException;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIVariant;
import org.openscada.opc.dcom.da.OPCBROWSEDIRECTION;
import org.openscada.opc.dcom.da.OPCBROWSETYPE;
import org.openscada.opc.dcom.da.OPCNAMESPACETYPE;
import org.openscada.opc.dcom.da.impl.OPCBrowseServerAddressSpace;
import org.openscada.opc.dcom.da.impl.OPCServer;
/**
* 遍历OPC连接下的所有Group和Item
*
* @author Freud
*
*/
public class DCOMTest2 {
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
/**
* Session获取
*/
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
final OPCBrowseServerAddressSpace serverBrowser = server.getBrowser();
/**
* Flat形式获取所有Item信息
*/
browseFlat(serverBrowser);
/**
* 获取所有的Group和Item信息
*/
browseTree(serverBrowser);
}
/**
* Tree形式获取所有Group和Item的信息
*/
private static void browseTree(final OPCBrowseServerAddressSpace browser)
throws IllegalArgumentException, UnknownHostException, JIException {
System.out.println("Showing hierarchial address space");
System.out.println(String.format("Organization: %s",
browser.queryOrganization()));
if (!browser.queryOrganization().equals(
OPCNAMESPACETYPE.OPC_NS_HIERARCHIAL)) {
return;
}
browser.changePosition(null, OPCBROWSEDIRECTION.OPC_BROWSE_TO);
browseTree(browser, 0);
}
private static String printTab(int level) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < level; i++) {
sb.append("\t");
}
return sb.toString();
}
private static void browseTree(final OPCBrowseServerAddressSpace browser,
final int level) throws JIException, IllegalArgumentException,
UnknownHostException {
for (final String item : browser.browse(OPCBROWSETYPE.OPC_LEAF, "", 0,
JIVariant.VT_EMPTY).asCollection()) {
System.out.println(printTab(level) + "Leaf: " + item + "\tName: "
+ browser.getItemID(item));
}
for (final String item : browser.browse(OPCBROWSETYPE.OPC_BRANCH, "",
0, JIVariant.VT_EMPTY).asCollection()) {
System.out.println(printTab(level) + "Branch: " + item);
browser.changePosition(item, OPCBROWSEDIRECTION.OPC_BROWSE_DOWN);
browseTree(browser, level + 1);
browser.changePosition(null, OPCBROWSEDIRECTION.OPC_BROWSE_UP);
}
}
/**
* Flat形式获取Item的信息
*/
private static void browseFlat(final OPCBrowseServerAddressSpace browser)
throws JIException, IllegalArgumentException, UnknownHostException {
System.out.println(String.format("Organization: %s",
browser.queryOrganization()));
browser.changePosition(null, OPCBROWSEDIRECTION.OPC_BROWSE_TO);
System.out.println("Showing flat address space");
for (final String id : browser.browse(OPCBROWSETYPE.OPC_FLAT, "", 0,
JIVariant.VT_EMPTY).asCollection()) {
System.out.println("Item: " + id);
}
}
}

View File

@@ -1,81 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import java.net.UnknownHostException;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.openscada.opc.dcom.da.OPCENUMSCOPE;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCServer;
/**
* 通过Scope遍历OPC连接下的所有Group信息
*
* @author Freud
*
*/
public class DCOMTest3 {
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
/**
* Session获取
*/
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
/**
* 添加一个Group的信息
*/
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
0.0f, 1033);
enumerateGroups(server, OPCENUMSCOPE.OPC_ENUM_PUBLIC);
enumerateGroups(server, OPCENUMSCOPE.OPC_ENUM_PRIVATE);
enumerateGroups(server, OPCENUMSCOPE.OPC_ENUM_ALL);
// clean up
server.removeGroup(group, true);
}
/**
* 通过Scope查找并遍历Groups的信息
*
* @param server
* @param scope
* @throws IllegalArgumentException
* @throws UnknownHostException
* @throws JIException
*/
public static void enumerateGroups(final OPCServer server,
final OPCENUMSCOPE scope) throws IllegalArgumentException,
UnknownHostException, JIException {
System.out.println("Enum Groups: " + scope.toString());
for (final String group : server.getGroups(scope).asCollection()) {
System.out.println("Group: " + group);
}
}
}

View File

@@ -1,221 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.openscada.opc.dcom.common.EventHandler;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.Result;
import org.openscada.opc.dcom.common.ResultSet;
import org.openscada.opc.dcom.common.impl.OPCCommon;
import org.openscada.opc.dcom.da.OPCDATASOURCE;
import org.openscada.opc.dcom.da.OPCITEMDEF;
import org.openscada.opc.dcom.da.OPCITEMRESULT;
import org.openscada.opc.dcom.da.OPCITEMSTATE;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
import org.openscada.opc.dcom.da.impl.OPCServer;
import org.openscada.opc.dcom.da.impl.OPCSyncIO;
/**
* 同步读取Item
*
* @author Freud
*
*/
public class DCOMTest4 {
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
/**
* Session获取
*/
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
/**
* 添加一个Group的信息
*/
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
0.0f, 1033);
testItems(server, group, new String[] { "Saw-toothed Waves.Int2",
"Saw-toothed Waves.test2" });
// clean up
server.removeGroup(group, true);
}
private static void showError(final OPCCommon common, final int errorCode)
throws JIException {
System.out.println(String.format("Error (%X): '%s'", errorCode,
common.getErrorString(errorCode, 1033)));
}
private static void showError(final OPCServer server, final int errorCode)
throws JIException {
showError(server.getCommon(), errorCode);
}
private static boolean dumpOPCITEMRESULT(
final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result) {
int failed = 0;
for (final KeyedResult<OPCITEMDEF, OPCITEMRESULT> resultEntry : result) {
System.out.println("==================================");
System.out.println(String.format("Item: '%s' ", resultEntry
.getKey().getItemID()));
System.out.println(String.format("Error Code: %08x",
resultEntry.getErrorCode()));
if (!resultEntry.isFailed()) {
System.out.println(String.format("Server Handle: %08X",
resultEntry.getValue().getServerHandle()));
System.out.println(String.format("Data Type: %d", resultEntry
.getValue().getCanonicalDataType()));
System.out.println(String.format("Access Rights: %d",
resultEntry.getValue().getAccessRights()));
System.out.println(String.format("Reserved: %d", resultEntry
.getValue().getReserved()));
} else {
failed++;
}
}
return failed == 0;
}
private static void testItems(final OPCServer server,
final OPCGroupStateMgt group, final String... itemIDs)
throws IllegalArgumentException, UnknownHostException, JIException {
final OPCItemMgt itemManagement = group.getItemManagement();
final List<OPCITEMDEF> items = new ArrayList<OPCITEMDEF>(itemIDs.length);
for (final String id : itemIDs) {
final OPCITEMDEF item = new OPCITEMDEF();
item.setItemID(id);
item.setClientHandle(new Random().nextInt());
items.add(item);
}
final OPCITEMDEF[] itemArray = items.toArray(new OPCITEMDEF[0]);
System.out.println("Validate");
KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement
.validate(itemArray);
if (!dumpOPCITEMRESULT(result)) {
return;
}
// now add them to the group
System.out.println("Add");
result = itemManagement.add(itemArray);
if (!dumpOPCITEMRESULT(result)) {
return;
}
// get the server handle array
final Integer[] serverHandles = new Integer[itemArray.length];
for (int i = 0; i < itemArray.length; i++) {
serverHandles[i] = new Integer(result.get(i).getValue()
.getServerHandle());
}
// set them active
System.out.println("Activate");
final ResultSet<Integer> resultSet = itemManagement.setActiveState(
true, serverHandles);
for (final Result<Integer> resultEntry : resultSet) {
System.out.println(String.format("Item: %08X, Error: %08X",
resultEntry.getValue(), resultEntry.getErrorCode()));
}
// set client handles
System.out.println("Set client handles");
final Integer[] clientHandles = new Integer[serverHandles.length];
for (int i = 0; i < serverHandles.length; i++) {
clientHandles[i] = i;
}
itemManagement.setClientHandles(serverHandles, clientHandles);
System.out.println("Create async IO 2.0 object");
// OPCAsyncIO2 asyncIO2 = group.getAsyncIO2 ();
// connect handler
System.out.println("attach");
final EventHandler eventHandler = group.attach(new DumpDataCallback());
// sleep
try {
System.out.println("Waiting...");
Thread.sleep(10 * 1000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
eventHandler.detach();
// sync IO - read
final OPCSyncIO syncIO = group.getSyncIO();
// OPCAsyncIO2 asyncIO2 = group.getAsyncIO2 ();
/*
* System.out.println ( "attach..enable" ); asyncIO2.setEnable ( true );
* System.out.println ( "attach..refresh" ); asyncIO2.refresh (
* (short)1, 1 );
*/
final KeyedResultSet<Integer, OPCITEMSTATE> itemState = syncIO.read(
OPCDATASOURCE.OPC_DS_DEVICE, serverHandles);
for (final KeyedResult<Integer, OPCITEMSTATE> itemStateEntry : itemState) {
final int errorCode = itemStateEntry.getErrorCode();
System.out
.println(String
.format("Server ID: %08X, Value: %s, Timestamp: %d/%d (%Tc), Quality: %d, Error: %08X",
itemStateEntry.getKey(), itemStateEntry
.getValue().getValue(),
itemStateEntry.getValue().getTimestamp()
.getHigh(),
itemStateEntry.getValue().getTimestamp()
.getLow(), itemStateEntry
.getValue().getTimestamp()
.asCalendar(), itemStateEntry
.getValue().getQuality(), errorCode));
if (errorCode != 0) {
showError(server, errorCode);
}
}
// set them inactive
System.out.println("In-Active");
itemManagement.setActiveState(false, serverHandles);
// finally remove them again
System.out.println("Remove");
itemManagement.remove(serverHandles);
}
}

View File

@@ -1,119 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import java.util.Collection;
import org.apache.log4j.Logger;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIVariant;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.da.PropertyDescription;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemProperties;
import org.openscada.opc.dcom.da.impl.OPCServer;
/**
* 获取指定Item的Properties
*
* @author Freud
*
*/
public class DCOMTest5 {
private static Logger LOGGER = Logger.getLogger(DCOMTest5.class);
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
/**
* Session获取
*/
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
/**
* 添加一个Group的信息
*/
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
0.0f, 1033);
final OPCItemProperties itemProperties = server
.getItemPropertiesService();
dumpItemProperties(itemProperties, "Saw-toothed Waves.Int");
// clean up
server.removeGroup(group, true);
LOGGER.info("test");
}
public static void dumpItemProperties(
final OPCItemProperties itemProperties, final String itemID)
throws JIException {
final Collection<PropertyDescription> properties = itemProperties
.queryAvailableProperties(itemID);
final int[] ids = new int[properties.size()];
System.out.println(String.format("Item Properties for '%s' (count:%d)",
itemID, properties.size()));
int i = 0;
for (final PropertyDescription pd : properties) {
ids[i] = pd.getId();
System.out.println("ID: " + pd.getId());
System.out.println("Description: " + pd.getDescription());
System.out.println("Variable Type: " + pd.getVarType());
i++;
}
System.out.println("Lookup");
dumpItemPropertiesLookup(itemProperties, itemID, ids);
System.out.println("Query");
dumpItemProperties2(itemProperties, itemID, ids);
}
public static void dumpItemProperties2(
final OPCItemProperties itemProperties, final String itemID,
final int... ids) throws JIException {
final KeyedResultSet<Integer, JIVariant> values = itemProperties
.getItemProperties(itemID, ids);
for (final KeyedResult<Integer, JIVariant> entry : values) {
System.out.println(String.format(
"ID: %d, Value: %s, Error Code: %08x", entry.getKey(),
entry.getValue().toString(), entry.getErrorCode()));
}
}
public static void dumpItemPropertiesLookup(
final OPCItemProperties itemProperties, final String itemID,
final int... ids) throws JIException {
final KeyedResultSet<Integer, String> values = itemProperties
.lookupItemIDs(itemID, ids);
for (final KeyedResult<Integer, String> entry : values) {
System.out.println(String.format(
"ID: %d, Item ID: %s, Error Code: %08x", entry.getKey(),
entry.getValue(), entry.getErrorCode()));
}
}
}

View File

@@ -1,70 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.openscada.opc.dcom.da.IORequest;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemIO;
import org.openscada.opc.dcom.da.impl.OPCServer;
/**
* Query指定的Item
*
* @author Freud
*
*/
public class DCOMTest6 {
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
/**
* Session获取
*/
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
/**
* 添加一个Group的信息
*/
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
0.0f, 1033);
final OPCItemIO itemIO = server.getItemIOService();
queryItems(itemIO, "Saw-toothed Waves.Int1");
// clean up
server.removeGroup(group, true);
}
public static void queryItems(final OPCItemIO itemIO, final String... items)
throws JIException {
final IORequest[] requests = new IORequest[items.length];
for (int i = 0; i < items.length; i++) {
requests[i] = new IORequest(items[i], 0);
}
itemIO.read(requests);
}
}

View File

@@ -1,203 +0,0 @@
package com.freud.dcom.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_CLSID;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIClsid;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JISession;
import org.openscada.opc.dcom.common.EventHandler;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.Result;
import org.openscada.opc.dcom.common.ResultSet;
import org.openscada.opc.dcom.common.impl.OPCCommon;
import org.openscada.opc.dcom.da.OPCDATASOURCE;
import org.openscada.opc.dcom.da.OPCITEMDEF;
import org.openscada.opc.dcom.da.OPCITEMRESULT;
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2;
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2.AsyncResult;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
import org.openscada.opc.dcom.da.impl.OPCServer;
/**
* 异步读取Item
*
* @author Freud
*
*/
public class DCOMTest7 {
public static void main(String[] args) throws Exception {
JISystem.setAutoRegisteration(true);
/**
* Session获取
*/
JISession _session = JISession.createSession(
getEntryValue(CONFIG_DOMAIN), getEntryValue(CONFIG_USERNAME),
getEntryValue(CONFIG_PASSWORD));
final JIComServer comServer = new JIComServer(
JIClsid.valueOf(getEntryValue(CONFIG_CLSID)),
getEntryValue(CONFIG_HOST), _session);
final IJIComObject serverObject = comServer.createInstance();
OPCServer server = new OPCServer(serverObject);
/**
* 添加一个Group的信息
*/
OPCGroupStateMgt group = server.addGroup("test", true, 100, 1234, 60,
0.0f, 1033);
testItems(group, new String[] { "Saw-toothed Waves.Int2" });
// clean up
server.removeGroup(group, true);
}
public static void testItems(final OPCGroupStateMgt group,
final String... itemIDs) throws IllegalArgumentException,
UnknownHostException, JIException {
final OPCItemMgt itemManagement = group.getItemManagement();
final List<OPCITEMDEF> items = new ArrayList<OPCITEMDEF>(itemIDs.length);
for (final String id : itemIDs) {
final OPCITEMDEF item = new OPCITEMDEF();
item.setItemID(id);
item.setClientHandle(new Random().nextInt());
items.add(item);
}
final OPCITEMDEF[] itemArray = items.toArray(new OPCITEMDEF[0]);
System.out.println("Validate");
KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result = itemManagement
.validate(itemArray);
if (!dumpOPCITEMRESULT(result)) {
return;
}
// now add them to the group
System.out.println("Add");
result = itemManagement.add(itemArray);
if (!dumpOPCITEMRESULT(result)) {
return;
}
// get the server handle array
final Integer[] serverHandles = new Integer[itemArray.length];
for (int i = 0; i < itemArray.length; i++) {
serverHandles[i] = new Integer(result.get(i).getValue()
.getServerHandle());
}
// set them active
System.out.println("Activate");
final ResultSet<Integer> resultSet = itemManagement.setActiveState(
true, serverHandles);
for (final Result<Integer> resultEntry : resultSet) {
System.out.println(String.format("Item: %08X, Error: %08X",
resultEntry.getValue(), resultEntry.getErrorCode()));
}
// set client handles
System.out.println("Set client handles");
final Integer[] clientHandles = new Integer[serverHandles.length];
for (int i = 0; i < serverHandles.length; i++) {
clientHandles[i] = i;
}
itemManagement.setClientHandles(serverHandles, clientHandles);
System.out.println("Create async IO 2.0 object");
final OPCAsyncIO2 asyncIO2 = group.getAsyncIO2();
// connect handler
System.out.println("attach");
final EventHandler eventHandler = group.attach(new DumpDataCallback());
System.out.println("attach..enable");
asyncIO2.setEnable(true);
System.out.println("attach..refresh");
final int cancelId = asyncIO2.refresh(OPCDATASOURCE.OPC_DS_DEVICE, 1);
System.out.println("Cancel ID: " + cancelId);
System.out.println("attach..read");
final AsyncResult asyncResult = asyncIO2.read(2, serverHandles);
System.out.println(String.format("attach..read..cancelId: %08X",
asyncResult.getCancelId()));
// sleep
try {
System.out.println("Waiting...");
Thread.sleep(10 * 1000);
} catch (final InterruptedException e) {
e.printStackTrace();
}
System.out.println("Detaching");
eventHandler.detach();
// set them inactive
System.out.println("In-Active");
itemManagement.setActiveState(false, serverHandles);
// finally remove them again
System.out.println("Remove");
itemManagement.remove(serverHandles);
}
public static void showError(final OPCCommon common, final int errorCode)
throws JIException {
System.out.println(String.format("Error (%X): '%s'", errorCode,
common.getErrorString(errorCode, 1033)));
}
public static void showError(final OPCServer server, final int errorCode)
throws JIException {
showError(server.getCommon(), errorCode);
}
public static boolean dumpOPCITEMRESULT(
final KeyedResultSet<OPCITEMDEF, OPCITEMRESULT> result) {
int failed = 0;
for (final KeyedResult<OPCITEMDEF, OPCITEMRESULT> resultEntry : result) {
System.out.println("==================================");
System.out.println(String.format("Item: '%s' ", resultEntry
.getKey().getItemID()));
System.out.println(String.format("Error Code: %08x",
resultEntry.getErrorCode()));
if (!resultEntry.isFailed()) {
System.out.println(String.format("Server Handle: %08X",
resultEntry.getValue().getServerHandle()));
System.out.println(String.format("Data Type: %d", resultEntry
.getValue().getCanonicalDataType()));
System.out.println(String.format("Access Rights: %d",
resultEntry.getValue().getAccessRights()));
System.out.println(String.format("Reserved: %d", resultEntry
.getValue().getReserved()));
} else {
failed++;
}
}
return failed == 0;
}
}

View File

@@ -1,59 +0,0 @@
package com.freud.dcom.utgard.cases;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.ResultSet;
import org.openscada.opc.dcom.da.IOPCDataCallback;
import org.openscada.opc.dcom.da.ValueData;
public class DumpDataCallback implements IOPCDataCallback {
public void cancelComplete(final int transactionId,
final int serverGroupHandle) {
System.out.println(String.format("cancelComplete: %08X, Group: %08X",
transactionId, serverGroupHandle));
}
public void dataChange(final int transactionId,
final int serverGroupHandle, final int masterQuality,
final int masterErrorCode,
final KeyedResultSet<Integer, ValueData> result) {
System.out.println(String.format(
"dataChange: %d, Group: %08X, MasterQ: %d, Error: %d",
transactionId, serverGroupHandle, masterQuality,
masterErrorCode));
for (final KeyedResult<Integer, ValueData> entry : result) {
System.out.println(String.format(
"%08X - Error: %08X, Quality: %d, %Tc - %s",
entry.getKey(), entry.getErrorCode(), entry.getValue()
.getQuality(), entry.getValue().getTimestamp(),
entry.getValue().getValue().toString()));
}
}
public void readComplete(final int transactionId,
final int serverGroupHandle, final int masterQuality,
final int masterErrorCode,
final KeyedResultSet<Integer, ValueData> result) {
System.out.println(String.format(
"readComplete: %d, Group: %08X, MasterQ: %d, Error: %d",
transactionId, serverGroupHandle, masterQuality,
masterErrorCode));
for (final KeyedResult<Integer, ValueData> entry : result) {
System.out.println(String.format(
"%08X - Error: %08X, Quality: %d, %Tc - %s",
entry.getKey(), entry.getErrorCode(), entry.getValue()
.getQuality(), entry.getValue().getTimestamp(),
entry.getValue().getValue().toString()));
}
}
public void writeComplete(final int transactionId,
final int serverGroupHandle, final int masterErrorCode,
final ResultSet<Integer> result) {
}
}

View File

@@ -1,10 +1,10 @@
package com.freud.opc.utgard;
import org.openscada.opc.lib.common.ConnectionInformation;
import java.io.IOException;
import java.util.Properties;
import org.openscada.opc.lib.common.ConnectionInformation;
/**
* 配置文件工具类
*
@@ -21,7 +21,7 @@ public final class BaseConfiguration {
public final static String CONFIG_HOST = "host";
public final static String CONFIG_DOMAIN = "domain";
public final static String CONFIG_CLSID = "clsid";
public final static String CONFIG_PROGID = "progid";
// public final static String CONFIG_PROGID = "progid";
private final static String CONFIG_FILE_NAME = "config.properties";
@@ -66,12 +66,12 @@ public final class BaseConfiguration {
*
* @return
*/
public static ConnectionInformation getPROGIDConnectionInfomation() {
ci.setClsid(null);
getConnectionInfomation();
ci.setProgId(prop.getProperty(CONFIG_PROGID));
return ci;
}
// public static ConnectionInformation getPROGIDConnectionInfomation() {
// ci.setClsid(null);
// getConnectionInfomation();
// ci.setProgId(prop.getProperty(CONFIG_PROGID));
// return ci;
// }
/**
* 获得基础的连接信息

View File

@@ -1,50 +0,0 @@
package com.freud.opc.utgard.cases;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_DOMAIN;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_HOST;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_PASSWORD;
import static com.freud.opc.utgard.BaseConfiguration.CONFIG_USERNAME;
import static com.freud.opc.utgard.BaseConfiguration.getEntryValue;
import java.util.Collection;
import org.openscada.opc.dcom.list.ClassDetails;
import org.openscada.opc.lib.list.Categories;
import org.openscada.opc.lib.list.Category;
import org.openscada.opc.lib.list.ServerList;
/**
* Get all the opc connection info from Server
*
* @author Freud
*
*/
public class OPCTest1 {
public static void main(String[] args) throws Exception {
ServerList serverList = new ServerList(getEntryValue(CONFIG_HOST),
getEntryValue(CONFIG_USERNAME), getEntryValue(CONFIG_PASSWORD),
getEntryValue(CONFIG_DOMAIN));
/** According the progid get the clsid, then get the classdetail */
// final String cls = serverList
// .getClsIdFromProgId("Matrikon.OPC.Simulation.1");
//
// ClassDetails cd = serverList.getDetails(cls);
//
// if (cd != null) {
// System.out.println(cd.getProgId() + "=" + cd.getDescription());
// }
Collection<ClassDetails> classDetails = serverList
.listServersWithDetails(new Category[] {
Categories.OPCDAServer10, Categories.OPCDAServer20,
Categories.OPCDAServer30 }, new Category[] {});
for (ClassDetails cds : classDetails) {
System.out.println(cds.getProgId() + "=" + cds.getDescription());
}
}
}

View File

@@ -43,7 +43,7 @@ public class OPCTest2 {
* @param browser
* @throws IllegalArgumentException
* @throws UnknownHostException
* @throws JIException
* @throws JIException JIException
*/
private static void dumpFlat(final FlatBrowser browser)
throws IllegalArgumentException, UnknownHostException, JIException {

View File

@@ -1,51 +0,0 @@
package com.freud.opc.utgard.cases;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Executors;
import org.jinterop.dcom.common.JIException;
import org.openscada.opc.lib.da.Group;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.Server;
import com.freud.opc.utgard.BaseConfiguration;
/**
* 同步读取某个点位的值
*
* @author Freud
*
*/
public class OPCTest3 {
public static void main(String[] args) throws Exception {
Server server = new Server(
BaseConfiguration.getCLSIDConnectionInfomation(),
Executors.newSingleThreadScheduledExecutor());
server.connect();
Group group = server.addGroup();
Item item = group.addItem("Random.Real5");
Map<String, Item> items = group.addItems("Random.Real1",
"Random.Real2", "Random.Real3", "Random.Real4");
dumpItem(item);
for (Entry<String, Item> temp : items.entrySet()) {
dumpItem(temp.getValue());
}
server.dispose();
}
private static void dumpItem(Item item) throws JIException {
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
+ "],value:" + item.read(false).getValue());
}
private static int count;
}

View File

@@ -1,63 +0,0 @@
package com.freud.opc.utgard.cases;
import java.util.concurrent.Executors;
import org.openscada.opc.lib.da.AccessBase;
import org.openscada.opc.lib.da.DataCallback;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState;
import org.openscada.opc.lib.da.Server;
import org.openscada.opc.lib.da.SyncAccess;
import com.freud.opc.utgard.BaseConfiguration;
/**
* 异步读取点位的信息,读取某个点的变化值
*
* @author Freud
*
*/
public class OPCTest4 {
/** 间隔时间 */
private static final int PERIOD = 100;
/** 休眠时间 */
private static final int SLEEP = 2000;
public static void main(String[] args) throws Exception {
Server server = new Server(
BaseConfiguration.getCLSIDConnectionInfomation(),
Executors.newSingleThreadScheduledExecutor());
server.connect();
/**
* 其中100单位为毫秒为每次从OPC获取刷新的间隔时间
*/
AccessBase access = new SyncAccess(server, PERIOD);
/**
* 定时每隔间隔时间获取一次值
*/
access.addItem("Random.Real5", new DataCallback() {
private int i;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++i) + "],ItemName:[" + item.getId()
+ "],value:" + itemstate.getValue());
}
});
/** 开始监听 */
access.bind();
/** 当前线程休眠时间单位:毫秒 */
Thread.sleep(SLEEP);
/** 监听 结束 */
access.unbind();
server.dispose();
}
}

View File

@@ -1,64 +0,0 @@
package com.freud.opc.utgard.cases;
import java.util.concurrent.Executors;
import org.openscada.opc.lib.da.AccessBase;
import org.openscada.opc.lib.da.Async20Access;
import org.openscada.opc.lib.da.DataCallback;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState;
import org.openscada.opc.lib.da.Server;
import com.freud.opc.utgard.BaseConfiguration;
/**
* 异步Access订阅读取点位的值,并且只有值有变化的时候才会触发CallBack函数
*
* @author Freud
*
*/
public class OPCTest5 {
/** 间隔时间 */
private static final int PERIOD = 100;
/** 休眠时间 */
private static final int SLEEP = 2000;
public static void main(String[] args) throws Exception {
Server server = new Server(
BaseConfiguration.getCLSIDConnectionInfomation(),
Executors.newSingleThreadScheduledExecutor());
server.connect();
/**
* 其中100单位为毫秒为每次从OPC获取刷新的间隔时间
*/
AccessBase access = new Async20Access(server, PERIOD, false);
/**
* 只有Item的值有变化的时候才会触发CallBack函数
*/
access.addItem("Random.Real5", new DataCallback() {
private int count;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++count) + "],ItemName:["
+ item.getId() + "],value:" + itemstate.getValue());
}
});
/** 开始监听 */
access.bind();
/** 当前线程休眠时间单位:毫秒 */
Thread.sleep(SLEEP);
/** 监听 结束 */
access.unbind();
server.dispose();
}
}

View File

@@ -1,67 +0,0 @@
package com.freud.opc.utgard.cases;
import java.util.concurrent.Executors;
import org.openscada.opc.lib.da.AccessBase;
import org.openscada.opc.lib.da.AutoReconnectController;
import org.openscada.opc.lib.da.DataCallback;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState;
import org.openscada.opc.lib.da.Server;
import org.openscada.opc.lib.da.SyncAccess;
import com.freud.opc.utgard.BaseConfiguration;
/**
* 如果Connection Break掉了会自动重新连接
*
* @author Freud
*
*/
public class OPCTest6 {
/** 间隔时间 */
private static final int PERIOD = 100;
/** 休眠时间 */
private static final int SLEEP = 2000;
public static void main(String[] args) throws Exception {
Server server = new Server(
BaseConfiguration.getCLSIDConnectionInfomation(),
Executors.newSingleThreadScheduledExecutor());
AutoReconnectController controller = new AutoReconnectController(server);
controller.connect();
/**
* 其中100单位为毫秒为每次从OPC获取刷新的间隔时间
*/
AccessBase access = new SyncAccess(server, PERIOD);
/**
* 定时每隔间隔时间获取一次值
*/
access.addItem("Random.Real5", new DataCallback() {
private int i;
public void changed(Item item, ItemState itemstate) {
System.out.println("[" + (++i) + "],ItemName:[" + item.getId()
+ "],value:" + itemstate.getValue());
}
});
/** 开始监听 */
access.bind();
/** 当前线程休眠时间单位:毫秒 */
Thread.sleep(SLEEP);
/** 监听结束 */
access.unbind();
controller.disconnect();
}
}

View File

@@ -1,55 +0,0 @@
package com.freud.opc.utgard.cases;
import java.util.concurrent.Executors;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.JIArray;
import org.jinterop.dcom.core.JIVariant;
import org.openscada.opc.lib.da.Group;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.Server;
import com.freud.opc.utgard.BaseConfiguration;
/**
* 同步写入某个点位的值
*
* @author Freud
*
*/
public class OPCTest7 {
public static void main(String[] args) throws Exception {
Server server = new Server(
BaseConfiguration.getCLSIDConnectionInfomation(),
Executors.newSingleThreadScheduledExecutor());
server.connect();
Group group = server.addGroup();
Item item = group.addItem("Square Waves.Real4");
/** 构造写入数据 */
final Float[] integerData = new Float[] { 1202f, 1203f, 1204f };
final JIArray array = new JIArray(integerData, false);
final JIVariant value = new JIVariant(array);
/** 同步写入 */
item.write(value);
Thread.sleep(2000);
/** Dump出item的值 */
dumpItem(item);
server.dispose();
}
private static void dumpItem(Item item) throws JIException {
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
+ "],value:" + item.read(true).getValue());
}
private static int count;
}

View File

@@ -1,54 +0,0 @@
package com.freud.opc.utgard.cases;
import java.util.concurrent.Executors;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.JIArray;
import org.jinterop.dcom.core.JIVariant;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.Server;
import com.freud.opc.utgard.BaseConfiguration;
/**
* 异步写入
*
* @author Freud
*
*/
@Deprecated
public class OPCTest8 {
public static void main(String[] args) throws Exception {
final Server server = new Server(
BaseConfiguration.getCLSIDConnectionInfomation(),
Executors.newSingleThreadScheduledExecutor());
server.connect();
/** 构造写入数据 */
final Float[] integerData = new Float[] { 1202f, 1203f, 1204f };
final JIArray array = new JIArray(integerData, false);
final JIVariant value = new JIVariant(array);
final Item item = server.addGroup().addItem("Square Waves.Real4");
/** 同步写入 */
item.write(value);
Thread.sleep(2000);
/** Dump出item的值 */
dumpItem(item);
server.dispose();
}
private static void dumpItem(Item item) throws JIException {
System.out.println("[" + (++count) + "],ItemName:[" + item.getId()
+ "],value:" + item.read(true).getValue());
}
private static int count;
}

View File

@@ -0,0 +1,927 @@
/*
* Copyright (c) 2022 Beijing Shuto Technology Co,. Ltd. All rights reserved.
*/
package org.jinterop.dcom.core;
import org.jinterop.dcom.common.*;
import org.jinterop.dcom.impls.JIObjectFactory;
import org.jinterop.dcom.impls.automation.IJIDispatch;
import org.jinterop.dcom.transport.JIComEndpoint;
import org.jinterop.dcom.transport.JIComTransportFactory;
import org.jinterop.winreg.IJIWinReg;
import org.jinterop.winreg.JIPolicyHandle;
import org.jinterop.winreg.JIWinRegFactory;
import rpc.Endpoint;
import rpc.FaultException;
import rpc.Stub;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Properties;
import java.util.logging.Level;
/** Startup class representing a COM Server.
* <p>
* Sample Usage :-
* <br>
* <code>
*
* {@link JISession} session = JISession.createSession("DOMAIN","USERNAME","PASSWORD"); <br>
* JIComServer excelServer = new JIComServer(JIProgId.valueOf("Excel.Application"),address,session); <br>
* IJIComObject comObject = excelServer.createInstance(); <br>
* //Obtaining the IJIDispatch (if supported) <br>
* {@link IJIDispatch} dispatch = (IJIDispatch){@link JIObjectFactory}.narrowObject(comObject.queryInterface(IJIDispatch.IID)); <br>
* </code>
*
* <p>Each instance of this class is associated with a single session only.
*
* @since 1.0
*
*/
public final class JIComServer extends Stub {
private static Properties defaults = new Properties();
static {
defaults.put("rpc.ntlm.lanManagerKey","false");
defaults.put("rpc.ntlm.sign","false");
defaults.put("rpc.ntlm.seal","false");
defaults.put("rpc.ntlm.keyExchange","false");
defaults.put("rpc.connectionContext","rpc.security.ntlm.NtlmConnectionContext");
defaults.put("rpc.socketTimeout", new Integer(0).toString());
// rpc.connectionContext = rpc.security.ntlm.NtlmConnectionContext
// rpc.ntlm.sign = false
// rpc.ntlm.seal = false
// rpc.ntlm.keyExchange = false
}
//private String address = null;
private JIRemActivation remoteActivation = null;
private JIOxidResolver oxidResolver = null;
private String clsid = null;
private String syntax = null;
private JISession session = null;
private boolean serverInstantiated = false;
private String remunknownIPID = null;
private final Object mutex = new Object();
private boolean timeoutModifiedfrom0 = false;
private JIInterfacePointer interfacePtrCtor = null;
private JIComServer(){}
/**<p> Instantiates a JIComServer represented by the interfacePointer param. There are cases where a COM server may hand down a
* reference to a different COM server(which may or may not be on the same machine) and we would like to hook in between.
* The <code>IJIComObject</code> interface is usable only in the context of the current JIComServer, but when the interfacePointer
* is of a completely different COM server, the JIObjectFactory APIs will not work. The reason is the interface pointer passed to those
* APIs expects to belong only to a single and same COM server (say 'A'). If by any chance, that COM server passes a reference to you
* of another COM server (say 'B') on a different machine, the <code>IJIComObject</code> so returned from <code>JIObjectFactory</code> APIs
* will result in "Method not found" Exceptions (or others) since the pointer returned via that will always place calls to 'A' instead of 'B'.
* Under such scenarios you must use this API. This is not a usual case and for reasons related to nature of DCOM, will be very well documented
* in the Developers guide of your COM server.
*
* <p>The DCOM specs refer to this as the "middleman" case. (Section 3.3.1) </p>
* </p>
* @param session Please use a new session and not an already bounded one. The <code>JISession.createSession(JISession)</code> can be used to create a new session.
* @param interfacePointer reference to a different COM server pointer.
* @param ipAddress Can be <code>null</code>. Sometimes there are many adapters (virtual as well) on the Target machine to which this interface pointer belongs,
* which may get sent as part of the interface pointer and consequently this call will fail since it is a possibility that IP is not reachable via this machine.
* The developer can send in the valid IP and if found in the interface pointer list will be used to talk to the target machine, overriding the other IP addresses present in the interface pointer.
* If this IP is not found then the "machine name" binding will be used. If this param is <code>null</code> then the first binding obtained from the interface pointer is used.
*/
JIComServer(JISession session, JIInterfacePointer interfacePointer,String ipAddress) throws JIException
{
super();
if (interfacePointer == null || session == null)
{
throw new IllegalArgumentException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_ILLEGAL_ARGUMENTS));
}
if (session.getStub() != null)
{
throw new JIException(JIErrorCodes.JI_SESSION_ALREADY_ESTABLISHED);
}
if (JISystem.getLogger().isLoggable(Level.INFO))
{
JISystem.internal_dumpMap();
}
super.setTransportFactory(JIComTransportFactory.getSingleTon());
//now read the session and prepare information for the stub.
super.setProperties(new Properties(defaults));
super.getProperties().setProperty("rpc.security.username", session.getUserName());
super.getProperties().setProperty("rpc.security.password", session.getPassword());
super.getProperties().setProperty("rpc.ntlm.domain", session.getDomain());
super.getProperties().setProperty("rpc.socketTimeout", new Integer(session.getGlobalSocketTimeout()).toString());
JIStringBinding[] addressBindings = interfacePointer.getStringBindings().getStringBindings();
int i = 0;
JIStringBinding binding = null;
JIStringBinding nameBinding = null;
String targetAddress = ipAddress == null ? "" : ipAddress.trim();
// if (!targetAddress.equals(""))
{
//now we choose, otherwise the first one we get.
while(i < addressBindings.length)
{
binding = addressBindings[i];
if (binding.getTowerId() != 0x07) //this means, even though I asked for TCPIP something else was supplied, noticed this in win2k.
{
i++;
continue;
}
//get the one with IP address
int index = binding.getNetworkAddress().indexOf(".");
if (index != -1)
{
try{
if (binding.getNetworkAddress().equalsIgnoreCase(targetAddress))
{
nameBinding = null;
break;
}
//now check for the one with port
index = binding.getNetworkAddress().indexOf("[");//this contains the port
if (index != -1 && binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
{
nameBinding = null;
break;
}
}catch(NumberFormatException e)
{
}
}
else
{
//can only come for the name, saving it incase nothing matches the target address
nameBinding = binding;
}
i++;
}
binding = nameBinding == null ? binding : nameBinding;
}
// else
// {
// //Just pick up the first one.
// binding = addressBindings[0];
// }
//will use this last binding .
//and currently only TCPIP is supported.
String address = binding.getNetworkAddress();
if (address.indexOf("[") == -1 )//this does not contain the port
{
String ipAddr = JISystem.getIPForHostName(address); //to use the binding supplied by the user.
if (ipAddr != null)
{
address = ipAddr;
}
//use 135
address = address + "[135]";
}
else
{
int index = address.indexOf("[");
String hostname = binding.getNetworkAddress().substring(0,index);
String ipAddr = JISystem.getIPForHostName(hostname); //to use the binding supplied by the user.
if (ipAddr != null)
{
address = ipAddr + address.substring(index);
}
}
super.setAddress("ncacn_ip_tcp:" + address);
this.session = session;
this.session.setTargetServer(getAddress().substring(getAddress().indexOf(":") + 1,getAddress().indexOf("[")));
oxidResolver = new JIOxidResolver(((JIStdObjRef)interfacePointer.getObjectReference(JIInterfacePointer.OBJREF_STANDARD)).getOxid());
try {
syntax = "99fcfec4-5260-101b-bbcb-00aa0021347a:0.0";
attach();
//first send an AlterContext to the IID of the IOxidResolver
getEndpoint().getSyntax().setUuid(new rpc.core.UUID("99fcfec4-5260-101b-bbcb-00aa0021347a"));
getEndpoint().getSyntax().setVersion(0,0);
((JIComEndpoint)getEndpoint()).rebindEndPoint();
call(Endpoint.IDEMPOTENT,oxidResolver);
}catch(FaultException e)
{
throw new JIException(e.status,e);
}
catch (IOException e) {
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
}catch (JIRuntimeException e1)
{
throw new JIException(e1);
}
// Now will setup syntax for IRemUnknown and the address.
//syntax = "00000143-0000-0000-c000-000000000046:0.0";
syntax = interfacePointer.getIID() + ":0.0";
//now for the new ip and the port.
JIStringBinding[] bindings = oxidResolver.getOxidBindings().getStringBindings();
binding = null;
nameBinding = null;
i = 0;
// if (!targetAddress.equals(""))
{
//now we choose, otherwise the first one we get.
while(i < bindings.length)
{
binding = bindings[i];
if (binding.getTowerId() != 0x07) //this means, even though I asked for TCPIP something else was supplied, noticed this in win2k.
{
i++;
continue;
}
//get the one with IP address
int index = binding.getNetworkAddress().indexOf(".");
if (index != -1)
{
try{
if (binding.getNetworkAddress().equalsIgnoreCase(targetAddress))
{
nameBinding = null;
break;
}
//now check for the one with port
index = binding.getNetworkAddress().indexOf("[");//this contains the port
if (index != -1 && binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
{
nameBinding = null;
break;
}
}catch(NumberFormatException e)
{
}
}
else
{
//can only come for the name, saving it incase nothing matches the target address
nameBinding = binding;
}
i++;
}
binding = nameBinding == null ? binding : nameBinding;
}
// else
// {
// //Just pick up the first one.
// binding = bindings[0];
// }
//now set the NTLMv2 Session Security.
if (session.isSessionSecurityEnabled())
{
super.getProperties().setProperty("rpc.ntlm.seal", "true");
super.getProperties().setProperty("rpc.ntlm.sign", "true");
super.getProperties().setProperty("rpc.ntlm.keyExchange", "true");
super.getProperties().setProperty("rpc.ntlm.keyLength", "128");
super.getProperties().setProperty("rpc.ntlm.ntlm2", "true");
}
address = binding.getNetworkAddress(); //this will always have the port.
int index = address.indexOf("[");
String hostname = binding.getNetworkAddress().substring(0,index);
String ipAddr = JISystem.getIPForHostName(hostname); //to use the binding supplied by the user.
if (ipAddr != null)
{
address = ipAddr + address.substring(index);
}
//and currently only TCPIP is supported.
setAddress("ncacn_ip_tcp:" + address);
remunknownIPID = oxidResolver.getIPID();
interfacePtrCtor = interfacePointer;
this.session.setStub(this);
}
/**<p><code>JIProgId</code> based constructor with the host machine for COM server being <i>LOCALHOST</i>.
*
* @param progId user-friendly string such as "Excel.Application" , "TestCOMServer.Test123" etc.
* @param session session to be associated with.
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
* @throws IllegalArgumentException raised when either <code>progId</code> or <code>session</code> is <code>null</code>.
* @throws UnknownHostException
*/
public JIComServer(JIProgId progId,JISession session) throws JIException, UnknownHostException
{
this(progId,InetAddress.getLocalHost().getHostAddress(),session);
}
/** <p><code>{@link JIClsid}</code> based constructor with the host machine for COM server being <i>LOCALHOST</i>.
*
* @param clsid 128 bit string such as "00024500-0000-0000-C000-000000000046".
* @param session session to be associated with.
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
* @throws IllegalArgumentException raised when either <code>clsid</code> or <code>session</code> is <code>null</code>.
* @throws UnknownHostException
*/
public JIComServer(JIClsid clsid,JISession session) throws IllegalArgumentException,JIException, UnknownHostException
{
this(clsid,InetAddress.getLocalHost().getHostAddress(),session);
}
/**<p>Refer {@link #JIComServer(JIProgId, JISession)} for details.
*
* @param progId user-friendly string such as "Excel.Application" , "TestCOMServer.Test123" etc.
* @param address address of the host where the <code>COM</code> object resides.This should be in the IEEE IP format (e.g. 192.168.170.6) or a resolvable HostName.
* @param session session to be associated with.
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
* @throws IllegalArgumentException raised when any of the parameters is <code>null</code>.
* @throws UnknownHostException
*/
public JIComServer(JIProgId progId,String address, JISession session) throws JIException, UnknownHostException
{
super();
if (progId == null || address == null || session == null)
{
throw new IllegalArgumentException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_ILLEGAL_ARGUMENTS));
}
if (session.getStub() != null)
{
throw new JIException(JIErrorCodes.JI_SESSION_ALREADY_ESTABLISHED);
}
address = address.trim();
address = InetAddress.getByName(address).getHostAddress();
progId.setSession(session);
progId.setServer(address);
address = "ncacn_ip_tcp:"+address+"[135]";
JIClsid clsid = progId.getCorrespondingCLSID();
initialise(clsid,address,session);
}
/** <p>Refer {@link #JIComServer(JIClsid, JISession)} for details.
*
*
* @param clsid 128 bit string such as "00024500-0000-0000-C000-000000000046".
* @param address address of the host where the <code>COM</code> object resides.This should be in the IEEE IP format (e.g. 192.168.170.6) or a resolvable HostName.
* @param session session to be associated with.
* @throws JIException will <i>also</i> get thrown in case the <code>session</code> is associated with another server already.
* @throws IllegalArgumentException raised when any of the parameters is <code>null</code>.
* @throws UnknownHostException
*/
public JIComServer(JIClsid clsid,String address, JISession session) throws JIException, UnknownHostException
{
super();
if (clsid == null || address == null || session == null)
{
throw new IllegalArgumentException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_ILLEGAL_ARGUMENTS));
}
if (session.getStub() != null)
{
throw new JIException(JIErrorCodes.JI_SESSION_ALREADY_ESTABLISHED);
}
if(address.indexOf('[') < 0) {
address = address.trim();
//address = address.replace(' ','');
address = "ncacn_ip_tcp:" + InetAddress.getByName(address).getHostAddress() + "[135]";
} else {
address = "ncacn_ip_tcp:" + address;
}
System.out.println("clsid = " + clsid + ", address = " + address + ", session = " + session);
initialise(clsid,address,session);
}
private void initialise(JIClsid clsid,String address, JISession session) throws JIException
{
super.setTransportFactory(JIComTransportFactory.getSingleTon());
//now read the session and prepare information for the stub.
super.setProperties(new Properties(defaults));
super.getProperties().setProperty("rpc.security.username", session.getUserName());
super.getProperties().setProperty("rpc.security.password", session.getPassword());
super.getProperties().setProperty("rpc.ntlm.domain", session.getDomain());
super.getProperties().setProperty("rpc.socketTimeout", new Integer(session.getGlobalSocketTimeout()).toString());
super.setAddress(address);
// if (session.isSessionSecurityEnabled())
// {
// super.getProperties().setProperty("rpc.ntlm.seal", "true");
// super.getProperties().setProperty("rpc.ntlm.sign", "true");
// super.getProperties().setProperty("rpc.ntlm.keyExchange", "true");
// super.getProperties().setProperty("rpc.ntlm.keyLength", "128");
// super.getProperties().setProperty("rpc.ntlm.ntlm2", "true");
// }
if (JISystem.getLogger().isLoggable(Level.INFO))
{
JISystem.internal_dumpMap();
}
this.clsid = clsid.getCLSID().toUpperCase();
this.session = session;
this.session.setTargetServer(address.substring(address.indexOf(":") + 1,address.indexOf("[")));
try{
init();
}catch(JIException e)
{
if (e.getErrorCode() == 0x80040154)
{
if (JISystem.getLogger().isLoggable(Level.WARNING))
{
JISystem.getLogger().warning("Got the class not registered exception , will attempt setting entries based on status flags...");
}
//try registering the dll\ocx on our own
//check for clsid.autoregister flag
//check for jisystem.autoregister flag.
//jisystem takes precedence over clsid.
if (JISystem.isAutoRegistrationSet() || clsid.isAutoRegistrationSet())
{
//first create the registry entries.
try {
IJIWinReg registry = null;
registry = JIWinRegFactory.getSingleTon().getWinreg(new JIDefaultAuthInfoImpl(session.getDomain(),session.getUserName(),session.getPassword()),session.getTargetServer(),true);
JIPolicyHandle hkcr = registry.winreg_OpenHKCR();
JIPolicyHandle key = registry.winreg_CreateKey(hkcr,"CLSID\\{" + this.clsid + "}",IJIWinReg.REG_OPTION_NON_VOLATILE,IJIWinReg.KEY_ALL_ACCESS );
registry.winreg_SetValue(key,"AppID",("{" + this.clsid + "}").getBytes(),false,false);
registry.winreg_CloseKey(key);
key = registry.winreg_CreateKey(hkcr,"AppID\\{" + this.clsid + "}",IJIWinReg.REG_OPTION_NON_VOLATILE,IJIWinReg.KEY_ALL_ACCESS );
registry.winreg_SetValue(key,"DllSurrogate"," ".getBytes(),false,false);
registry.winreg_CloseKey(key);
registry.winreg_CloseKey(hkcr);
registry.closeConnection();
} catch (UnknownHostException e1) {
//auto registration failed as well...
JISystem.getLogger().throwing("JIComServer","initialise",e1);
throw new JIException(JIErrorCodes.JI_WINREG_EXCEPTION3,e1);
}
//lets retry
init();
}
else
{
throw e;
}
}
else
{
throw e;
}
}
this.session.setStub(this);
}
private void init () throws JIException
{
if (remoteActivation != null && remoteActivation.isActivationSuccessful())
{
return;
}
boolean attachcomplete = false;
try {
syntax = "99fcfec4-5260-101b-bbcb-00aa0021347a:0.0";
attach();
// socket to COM server is established
attachcomplete = true;
//first send an AlterContext to the IID of the IOxidResolver
getEndpoint().getSyntax().setUuid(new rpc.core.UUID("99fcfec4-5260-101b-bbcb-00aa0021347a"));
getEndpoint().getSyntax().setVersion(0,0);
((JIComEndpoint)getEndpoint()).rebindEndPoint();
//setup syntax for IRemoteActivation
syntax = "4d9f4ab8-7d1c-11cf-861e-0020af6e7c57:0.0";
getEndpoint().getSyntax().setUuid(new rpc.core.UUID("4d9f4ab8-7d1c-11cf-861e-0020af6e7c57"));
getEndpoint().getSyntax().setVersion(0,0);
((JIComEndpoint)getEndpoint()).rebindEndPoint();
remoteActivation = new JIRemActivation(clsid);
call(Endpoint.IDEMPOTENT,remoteActivation);
}catch(FaultException e)
{
remoteActivation = null;
throw new JIException(e.status,e);
}
catch (IOException e) {
remoteActivation = null;
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
}catch (JIRuntimeException e1)
{
remoteActivation = null;
throw new JIException(e1);
}
finally
{
//the only time remactivation will be null will be case of an exception.
if (attachcomplete && remoteActivation == null)
{
try {
detach();
} catch (IOException e) {
if (JISystem.getLogger().isLoggable(Level.WARNING))
{
JISystem.getLogger().warning("Unable to detach during init: " + e);
}
}
}
}
// Now will setup syntax for IRemUnknown and the address.
syntax = "00000143-0000-0000-c000-000000000046:0.0";
//now for the new ip and the port.
JIStringBinding[] bindings = remoteActivation.getDualStringArrayForOxid().getStringBindings();
int i = 0;
JIStringBinding binding = null;
JIStringBinding nameBinding = null;
String targetAddress = getAddress();
targetAddress = targetAddress.substring(targetAddress.indexOf(':') + 1,targetAddress.indexOf('['));
while(i < bindings.length)
{
binding = bindings[i];
if (binding.getTowerId() != 0x07) //this means, even though I asked for TCPIP something else was supplied, noticed this in win2k.
{
i++;
continue;
}
//get the one with IP address
int index = binding.getNetworkAddress().indexOf(".");
if (index != -1)
{
try{
//Integer.parseInt(binding.getNetworkAddress().substring(0,index));
index = binding.getNetworkAddress().indexOf("[");//this contains the port
if (index != -1 && binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
{
break;
}
}catch(NumberFormatException e)
{
}
}
else
{
//can only come for the name, saving it incase nothing matches the target address
//then we are not sure which is the right IP and which might be virtual, refer to
//issue faced by Igor.
nameBinding = binding;
index = binding.getNetworkAddress().indexOf("[");//this contains the port
if (binding.getNetworkAddress().substring(0,index).equalsIgnoreCase(targetAddress))
{
break;
}
}
i++;
}
if (binding == null)
{
binding = nameBinding;
}
//will use this last binding .
//and currently only TCPIP is supported.
//now set the NTLMv2 Session Security.
if (session.isSessionSecurityEnabled())
{
super.getProperties().setProperty("rpc.ntlm.seal", "true");
super.getProperties().setProperty("rpc.ntlm.sign", "true");
super.getProperties().setProperty("rpc.ntlm.keyExchange", "true");
super.getProperties().setProperty("rpc.ntlm.keyLength", "128");
super.getProperties().setProperty("rpc.ntlm.ntlm2", "true");
}
String address = binding.getNetworkAddress(); //this will always have the port.
int index = address.indexOf("[");
String hostname = binding.getNetworkAddress().substring(0,index);
String ipAddr = JISystem.getIPForHostName(hostname); //to use the binding supplied by the user.
if (ipAddr != null)
{
address = ipAddr + address.substring(index);
}
//and currently only TCPIP is supported.
setAddress("ncacn_ip_tcp:" + address);
// setAddress("ncacn_ip_tcp:" + binding.getNetworkAddress());
remunknownIPID = remoteActivation.getIPID();
}
//Will give a call to IRemUnknown for the passed IID.
IJIComObject getInterface(String iid,String ipidOfTheTargetUnknown) throws JIException
{
IJIComObject retval = null;
//this is still essentially serial, since all threads will have to wait for mutex before
//entering addToSession.
synchronized (mutex) {
//now also set the Object ID for IRemUnknown call this will be the IPID of the returned JIRemActivation
setObject(remunknownIPID);
//setObject(ipid);
//JIRemUnknown reqUnknown = new JIRemUnknown(unknownIPID,iid,5);
JIRemUnknown reqUnknown = new JIRemUnknown(ipidOfTheTargetUnknown,iid);
try {
call(Endpoint.IDEMPOTENT,reqUnknown);
}catch(FaultException e)
{
throw new JIException(e.status,e);
}
catch (IOException e) {
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
}catch (JIRuntimeException e1)
{
//remoteActivation = null;
throw new JIException(e1);
}
retval = JIFrameworkHelper.instantiateComObject(session, reqUnknown.getInterfacePointer());
//increasing the reference count.
retval.addRef();
//for querying dispatch we can't send another call
if (!iid.equalsIgnoreCase("00020400-0000-0000-c000-000000000046"))
{
boolean success = true;
((JIComObjectImpl)retval).setIsDual(true);
//now to check whether it supports IDispatch
//IDispatch 00020400-0000-0000-c000-000000000046
JIRemUnknown dispatch = new JIRemUnknown(retval.getIpid(),"00020400-0000-0000-c000-000000000046");
try {
call(Endpoint.IDEMPOTENT,dispatch);
}catch(FaultException e)
{
throw new JIException(e.status,e);
}catch (IOException e) {
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
}catch (JIRuntimeException e1)
{
//will eat this exception here.
((JIComObjectImpl)retval).setIsDual(false);
success = false;
}
if (success)
{
//which means that IDispatch is supported
session.releaseRef(dispatch.getInterfacePointer().getIPID());
}
}
}
return retval;
}
/**Returns an <code>IJIComObject</code> representing the COM Server.
*
* @return
* @throws JIException
*/
public IJIComObject createInstance() throws JIException
{
if (interfacePtrCtor != null)
{
throw new IllegalStateException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_WRONGCALLCREATEINSTANCE));
}
IJIComObject comObject = null;
//This method is still essentially serial, since all threads will have to stop at mutex and then
//go to addToSession after it (since there is no condition).
synchronized (mutex) {
if (serverInstantiated)
{
throw new JIException(JIErrorCodes.JI_OBJECT_ALREADY_INSTANTIATED,(Throwable)null);
}
// JIStdObjRef objRef = (JIStdObjRef)(remoteActivation.getMInterfacePointer().getObjectReference(JIInterfacePointer.OBJREF_STANDARD));
// comObject = getObject(objRef.getIpid(),IJIUnknown.IID);
comObject = JIFrameworkHelper.instantiateComObject(session, remoteActivation.getMInterfacePointer());
if (remoteActivation.isDual)
{
//IJIComObject comObject2 = getObject(remoteActivation.dispIpid,"00020400-0000-0000-c000-000000000046");
//this will get garbage collected and then removed.
//session.addToSession(comObject2,remoteActivation.dispOid);
session.releaseRef(remoteActivation.dispIpid);
remoteActivation.dispIpid = null;
((JIComObjectImpl)comObject).setIsDual(true);
}
else
{
((JIComObjectImpl)comObject).setIsDual(false);
}
//increasing the reference count.
comObject.addRef();
serverInstantiated = true;
}
return comObject;
}
/**Returns a <code>IJIComObject</code> representing the <code>COM</code> Server. To be used only with <code>JIComServer(JISession,JIInterfacePointer,String)</code> ctor,
* otherwise use createInstance() instead.
*
* @return
* @throws JIException
*/
IJIComObject getInstance() throws JIException
{
if (interfacePtrCtor == null)
{
throw new IllegalStateException(JISystem.getLocalizedMessage(JIErrorCodes.JI_COMSTUB_WRONGCALLGETINSTANCE));
}
IJIComObject comObject = null;
//This method is still essentially serial, since all threads will have to stop at mutex and then
//go to addToSession after it (since there is no condition).
synchronized (mutex) {
if (serverInstantiated)
{
throw new JIException(JIErrorCodes.JI_OBJECT_ALREADY_INSTANTIATED,(Throwable)null);
}
// JIStdObjRef objRef = (JIStdObjRef)(interfacePtrCtor.getObjectReference(JIInterfacePointer.OBJREF_STANDARD));
// comObject = getObject(objRef.getIpid(),interfacePtrCtor.getIID());
comObject = JIFrameworkHelper.instantiateComObject(session,interfacePtrCtor);
//increasing the reference count.
comObject.addRef();
serverInstantiated = true;
}
return comObject;
}
protected String getSyntax() {
return syntax;
}
// /**
// * @exclude
// * @return
// */
// String getIpid()
// {
// if (remoteActivation != null && remoteActivation.isActivationSuccessful())
// {
// return remoteActivation.getIPID();
// }
// else
// return null;
// }
/** Execute a Method on the COM Interface identified by the IID.
*
*
* @exclude
* @param obj
* @param targetIID
* @return
* @throws JIException
*/
Object[] call(JICallBuilder obj,String targetIID) throws JIException
{
return call(obj, targetIID, session.getGlobalSocketTimeout());
}
/** Execute a Method on the COM Interface identified by the IID
*
*
* @exclude
* @param obj
* @param targetIID
* @return
* @throws JIException
*/
Object[] call(JICallBuilder obj,String targetIID, int socketTimeout) throws JIException
{
synchronized (mutex) {
if (session.isSessionInDestroy() && !obj.fromDestroySession)
{
throw new JIException(JIErrorCodes.JI_SESSION_DESTROYED);
}
if (socketTimeout != 0)
{
setSocketTimeOut(socketTimeout);
}
else //for cases where it was something earlier, but is now being set to 0.
{
if (timeoutModifiedfrom0)
{
setSocketTimeOut(socketTimeout);
}
}
try {
attach();
if (!getEndpoint().getSyntax().getUuid().toString().equalsIgnoreCase(targetIID))
{
//first send an AlterContext to the IID of the interface
getEndpoint().getSyntax().setUuid(new rpc.core.UUID(targetIID));
getEndpoint().getSyntax().setVersion(0,0);
((JIComEndpoint)getEndpoint()).rebindEndPoint();
}
setObject(obj.getParentIpid());
call(Endpoint.IDEMPOTENT,obj);
}catch(FaultException e)
{
throw new JIException(e.status,e);
}catch (IOException e) {
throw new JIException(JIErrorCodes.RPC_E_UNEXPECTED,e);
}catch (JIRuntimeException e1)
{
throw new JIException(e1);
}
return obj.getResults();
}
}
/**
* @exclude
* @return
*/
JIInterfacePointer getServerInterfacePointer()
{
//remoteactivation can be null only incase of OxidResolver ctor getting called.
return remoteActivation == null ? interfacePtrCtor : remoteActivation.getMInterfacePointer();
}
void addRef_ReleaseRef(JICallBuilder obj) throws JIException
{
synchronized (mutex) {
if (remunknownIPID == null)
{
return;
}
//now also set the Object ID for IRemUnknown call this will be the IPID of the returned JIRemActivation or IOxidResolver
obj.setParentIpid(remunknownIPID);
obj.attachSession(session);
try {
call(obj,JIRemUnknown.IID_IUnknown);
} catch (JIRuntimeException e1)
{
throw new JIException(e1);
}
}
}
void closeStub()
{
try {
detach();
} catch (IOException e) {
e.printStackTrace();
}
}
void setSocketTimeOut(int timeout)
{
if (timeout == 0)
{
timeoutModifiedfrom0 = false;
}
else
{
timeoutModifiedfrom0 = true;
}
getProperties().setProperty("rpc.socketTimeout", new Integer(timeout).toString());
}
}

View File

@@ -1,6 +0,0 @@
host=10.1.5.123
domain=
username=Freud
password=
clsid=F8582CF2-88FB-11D0-B850-00C0F0104305
progid=

View File

@@ -0,0 +1,7 @@
host=192.168.200.248[5150]
domain=
username=administrator
password=befar111
clsid=2C44004E-4C35-4b99-91C9-1DF6A623DF27
#progid==Kepware.KEPServerEX.V6

View File

@@ -6,16 +6,6 @@
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.kohsuke.jinterop</groupId>
@@ -23,16 +13,10 @@
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.openscada.opc.dcom</groupId>
<artifactId>org.openscada.opc.dcom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.openscada.utgard</groupId>
<artifactId>org.openscada.opc.lib</artifactId>
<version>1.1.0.v20130529</version>
<version>1.1.1</version>
</dependency>
</dependencies>

View File

@@ -1 +0,0 @@
bin/

View File

@@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@@ -1,31 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openscada.opc.dcom.test</groupId>
<artifactId>org.openscada.opc.dcom.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.kohsuke.jinterop</groupId>
<artifactId>j-interop</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.openscada.opc.dcom</groupId>
<artifactId>org.openscada.opc.dcom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -3,24 +3,84 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.openscada.opc.dcom</groupId>
<artifactId>org.openscada.opc.dcom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.kohsuke.jinterop</groupId>
<artifactId>j-interop</artifactId>
<version>2.0.5</version>
</dependency>
</dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<encoding>UTF-8</encoding>
<!-- <aggregate>true</aggregate>-->
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>shuto-public</id>
<name>Shuto Public</name>
<url>https://m.shuto.cn:8182/repository/maven-public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>shuto-release</id> <!--四个id 要保持一致-->
<url>https://m.shuto.cn:8182/repository/maven-releases/</url> <!-- distributionManagement里面url可改为自己的私仓地址-->
</repository>
</distributionManagement>
</project>

View File

@@ -32,7 +32,7 @@ public class Helper
* @param object the object to make to call on
* @param callObject the call object
* @return the result of the call
* @throws JIException
* @throws JIException JIException
*/
public static Object[] callRespectSFALSE ( final IJIComObject object, final JICallBuilder callObject ) throws JIException
{
@@ -55,7 +55,7 @@ public class Helper
* only changes control information on the variant and not the value itself!
* @param value the value to fix
* @return the fixed value
* @throws JIException In case something goes wrong
* @throws JIException JIException In case something goes wrong
*/
public static JIVariant fixVariant ( final JIVariant value ) throws JIException
{

View File

@@ -104,7 +104,7 @@ public class OPCITEMDEF
* Convert to structure to a J-Interop structure
*
* @return the j-interop structe
* @throws JIException
* @throws JIException JIException JIException
*/
public JIStruct toStruct () throws JIException
{

View File

@@ -26,7 +26,7 @@ import org.jinterop.dcom.core.JIVariant;
/**
* Data for a write request to the server
*
* @author Jens Reimann <jens.reimann@th4-systems.com>
* @author Jens Reimann <a href="mailto:jens.reimann@th4-systems.com">jens.reimann@th4-systems.com</a>
*/
public class WriteRequest
{

View File

@@ -19,14 +19,8 @@
package org.openscada.opc.dcom.da.impl;
import java.net.UnknownHostException;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JICallBuilder;
import org.jinterop.dcom.core.JIFlags;
import org.jinterop.dcom.core.JIPointer;
import org.jinterop.dcom.core.JIString;
import org.jinterop.dcom.core.*;
import org.openscada.opc.dcom.common.impl.BaseCOMObject;
import org.openscada.opc.dcom.common.impl.EnumString;
import org.openscada.opc.dcom.common.impl.Helper;
@@ -35,9 +29,11 @@ import org.openscada.opc.dcom.da.OPCBROWSEDIRECTION;
import org.openscada.opc.dcom.da.OPCBROWSETYPE;
import org.openscada.opc.dcom.da.OPCNAMESPACETYPE;
import java.net.UnknownHostException;
/**
* Implementation for <code>IOPCBrowseServerAddressSpace</code>
* @author Jens Reimann <jens.reimann@th4-systems.com>
* @author Jens Reimann <a href="mailto:jens.reimann@th4-systems.com">jens.reimann@th4-systems.com</a>
*
*/
public class OPCBrowseServerAddressSpace extends BaseCOMObject
@@ -50,7 +46,7 @@ public class OPCBrowseServerAddressSpace extends BaseCOMObject
/**
* Get the information how the namespace is organized
* @return the organization of the namespace
* @throws JIException
* @throws JIException JIException JIException
*/
public OPCNAMESPACETYPE queryOrganization () throws JIException
{
@@ -79,7 +75,7 @@ public class OPCBrowseServerAddressSpace extends BaseCOMObject
*
* @param position The item position reference for the direction
* @param direction The direction to go based on the position
* @throws JIException
* @throws JIException JIException JIException
*/
public void changePosition ( final String position, final OPCBROWSEDIRECTION direction ) throws JIException
{
@@ -113,9 +109,9 @@ public class OPCBrowseServerAddressSpace extends BaseCOMObject
* Return the possible access paths for an item
* @param itemID the item to query
* @return A string enumerator for the possible access paths
* @throws JIException
* @throws IllegalArgumentException
* @throws UnknownHostException
* @throws JIException JIException JIException
* @throws IllegalArgumentException IllegalArgumentException
* @throws UnknownHostException UnknownHostException
*/
public EnumString browseAccessPaths ( final String itemID ) throws JIException, IllegalArgumentException, UnknownHostException
{
@@ -140,7 +136,7 @@ public class OPCBrowseServerAddressSpace extends BaseCOMObject
*
* @param item the local item
* @return the complete item ID
* @throws JIException
* @throws JIException JIException JIException
*/
public String getItemID ( final String item ) throws JIException
{

View File

@@ -19,15 +19,8 @@
package org.openscada.opc.dcom.da.impl;
import java.net.UnknownHostException;
import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JICallBuilder;
import org.jinterop.dcom.core.JIFlags;
import org.jinterop.dcom.core.JIFrameworkHelper;
import org.jinterop.dcom.core.JIPointer;
import org.jinterop.dcom.core.JIString;
import org.jinterop.dcom.core.*;
import org.jinterop.dcom.impls.JIObjectFactory;
import org.openscada.opc.dcom.common.EventHandler;
import org.openscada.opc.dcom.common.impl.BaseCOMObject;
@@ -35,10 +28,12 @@ import org.openscada.opc.dcom.da.Constants;
import org.openscada.opc.dcom.da.IOPCDataCallback;
import org.openscada.opc.dcom.da.OPCGroupState;
import java.net.UnknownHostException;
/**
* Implementation of <code>IOPCGroupStateMgt</code>
*
* @author Jens Reimann <jens.reimann@th4-systems.com>
* @author Jens Reimann <a href="mailto:jens.reimann@th4-systems.com">jens.reimann@th4-systems.com</a>
*/
public class OPCGroupStateMgt extends BaseCOMObject
{
@@ -92,7 +87,7 @@ public class OPCGroupStateMgt extends BaseCOMObject
* @param clientHandle
* the client handle
* @return the granted update rate
* @throws JIException
* @throws JIException JIException
*/
public int setState ( final Integer requestedUpdateRate, final Boolean active, final Integer timeBias, final Float percentDeadband, final Integer localeID, final Integer clientHandle ) throws JIException
{
@@ -130,7 +125,7 @@ public class OPCGroupStateMgt extends BaseCOMObject
*
* @param name
* the new name
* @throws JIException
* @throws JIException JIException
*/
public void setName ( final String name ) throws JIException
{
@@ -148,7 +143,7 @@ public class OPCGroupStateMgt extends BaseCOMObject
* @param name
* the name of the cloned group
* @return The cloned group
* @throws JIException
* @throws JIException JIException
* @throws UnknownHostException
* @throws IllegalArgumentException
*/
@@ -171,7 +166,7 @@ public class OPCGroupStateMgt extends BaseCOMObject
* @param callback
* The callback to attach
* @return The event handler information
* @throws JIException
* @throws JIException JIException
*/
public EventHandler attach ( final IOPCDataCallback callback ) throws JIException
{

View File

@@ -45,7 +45,7 @@ public class OPCServer extends BaseCOMObject
/**
* Retrieve the current server status
* @return the current server status
* @throws JIException
* @throws JIException JIException
*/
public OPCSERVERSTATUS getStatus () throws JIException
{
@@ -115,7 +115,7 @@ public class OPCServer extends BaseCOMObject
* Get the groups
* @param scope The scope to get
* @return A string enumerator with the groups
* @throws JIException
* @throws JIException JIException
* @throws IllegalArgumentException
* @throws UnknownHostException
*/

View File

@@ -75,7 +75,7 @@ public class OPCServerList extends BaseCOMObject
/**
* Return details about a serve class
* @param clsId A server class
* @throws JIException
* @throws JIException JIException
*/
public ClassDetails getClassDetails ( final JIClsid clsId ) throws JIException
{

View File

@@ -1 +0,0 @@
bin/

View File

@@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@@ -1,37 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openscada.opc.lib.test</groupId>
<artifactId>org.openscada.opc.lib.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.kohsuke.jinterop</groupId>
<artifactId>j-interop</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.openscada.opc.dcom</groupId>
<artifactId>org.openscada.opc.dcom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.openscada.utgard</groupId>
<artifactId>org.openscada.opc.lib</artifactId>
<version>1.1.0.v20130529</version>
</dependency>
</dependencies>
</project>

View File

@@ -4,18 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.openscada.utgard</groupId>
<artifactId>org.openscada.opc.lib</artifactId>
<version>1.1.0.v20130529</version>
<version>1.1.2</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<artifactId>slf4j-api</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
@@ -26,8 +21,76 @@
<dependency>
<groupId>org.openscada.opc.dcom</groupId>
<artifactId>org.openscada.opc.dcom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<encoding>UTF-8</encoding>
<!-- <aggregate>true</aggregate>-->
<charset>UTF-8</charset>
<docencoding>UTF-8</docencoding>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>shuto-public</id>
<name>Shuto Public</name>
<url>https://m.shuto.cn:8182/repository/maven-public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>shuto-release</id> <!--四个id 要保持一致-->
<url>https://m.shuto.cn:8182/repository/maven-releases/</url> <!-- distributionManagement里面url可改为自己的私仓地址-->
</repository>
</distributionManagement>
</project>

View File

@@ -21,7 +21,7 @@ package org.openscada.opc.lib.common;
/**
* Holds the connection information
* @author Jens Reimann <jens.reimann@th4-systems.com>
* @author Jens Reimann <a href="mailto:jens.reimann@th4-systems.com">jens.reimann@th4-systems.com</a>
*
* If both <code>clsId</code> and <code>progId</code> are set then <code>clsId</code>
* has priority!

View File

@@ -19,27 +19,9 @@
package org.openscada.opc.lib.da;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import org.jinterop.dcom.common.JIException;
import org.openscada.opc.dcom.common.EventHandler;
import org.openscada.opc.dcom.common.KeyedResult;
import org.openscada.opc.dcom.common.KeyedResultSet;
import org.openscada.opc.dcom.common.Result;
import org.openscada.opc.dcom.common.ResultSet;
import org.openscada.opc.dcom.da.IOPCDataCallback;
import org.openscada.opc.dcom.da.OPCDATASOURCE;
import org.openscada.opc.dcom.da.OPCITEMDEF;
import org.openscada.opc.dcom.da.OPCITEMRESULT;
import org.openscada.opc.dcom.da.OPCITEMSTATE;
import org.openscada.opc.dcom.common.*;
import org.openscada.opc.dcom.da.*;
import org.openscada.opc.dcom.da.impl.OPCAsyncIO2;
import org.openscada.opc.dcom.da.impl.OPCGroupStateMgt;
import org.openscada.opc.dcom.da.impl.OPCItemMgt;
@@ -47,6 +29,9 @@ import org.openscada.opc.dcom.da.impl.OPCSyncIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.UnknownHostException;
import java.util.*;
public class Group
{
private static Logger _log = LoggerFactory.getLogger ( Group.class );
@@ -86,7 +71,7 @@ public class Group
/**
* remove the group from the server
* @throws JIException
* @throws JIException JIException
*
*/
public void remove () throws JIException
@@ -102,7 +87,7 @@ public class Group
/**
* Get the group name from the server
* @return The group name fetched from the server
* @throws JIException
* @throws JIException JIException
*/
public String getName () throws JIException
{
@@ -112,7 +97,7 @@ public class Group
/**
* Change the group name
* @param name the new name of the group
* @throws JIException
* @throws JIException JIException
*/
public void setName ( final String name ) throws JIException
{
@@ -124,7 +109,7 @@ public class Group
* one paraemter
* @param item The item to add
* @return The added item
* @throws JIException The add operation failed
* @throws JIException JIException The add operation failed
* @throws AddFailedException The item was not added due to an error
*/
public Item addItem ( final String item ) throws JIException, AddFailedException
@@ -141,7 +126,7 @@ public class Group
* lets the item pass validation it must also let them pass the add operation.
* @param items The items to validate
* @return A result map of item id to result information (including error code).
* @throws JIException
* @throws JIException JIException
*/
public synchronized Map<String, Result<OPCITEMRESULT>> validateItems ( final String... items ) throws JIException
{
@@ -167,7 +152,7 @@ public class Group
* Add new items to the group
* @param items The items (by string id) to add
* @return A result map of id to item object
* @throws JIException The add operation completely failed. No item was added.
* @throws JIException JIException The add operation completely failed. No item was added.
* @throws AddFailedException If one or more item could not be added. Item without error where added.
*/
public synchronized Map<String, Item> addItems ( final String... items ) throws JIException, AddFailedException

Some files were not shown because too many files have changed in this diff Show More