943,962 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4970
  • C# RSS
Jan 23rd, 2005
0

java to c#

Expand Post »
i am trying to make a program in c# based off another program that was written in java i would like to know if anyone nows what syntax you use to link other source files to your program.
in other words the c# equivalent to java's import code.
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Feb 9th, 2005
0

Re: java to c#

Quote ...
Overview
Java Language Conversion Assistant is a tool that automatically converts existing Java-language code into Visual C#® for developers who want to move existing applications to the .NET Framework.

Java Language Conversion Assistant provides developers using Visual Studio .NET 2003 a quick, low-cost method of converting Java-language applications to Visual C# and the .NET Framework. These applications can then be extended to utilize XML Web services and the complete .NET developer platform, including ASP.NET, ADO.NET, and Microsoft Windows® Forms.
This is a blurb from Microsoft, the software is a free download from them. Should give you a clue about the import question.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 9th, 2005
0

Re: java to c#

thank you.
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Mar 6th, 2008
0

Re: java to c#

import sysinfo
import e32
import os
import os.path
import re
import time
import urllib
import contacts
import codecs

CODEC='utf-16'
CVSFILENAME='E:\\contactsdb.cvs'

def getFieldtypenames():
"Return the list of fields"
dic = contacts.fieldtypemap
num = [[v,k] for k,v in dic.items()]
num.sort()
if num[0][0]==0 and num[0][1]=='none':
del num[0]
return [v for k,v in num]


def exportContacts(filename):
messages = []

f = None
try:
f = codecs.open(filename,'w+',CODEC)
except:
print 'error creation file'

if not f:
return -1

fields = getFieldtypenames()
fieldformat = u''.join(['%('+v+')s,' for v in fields ])[0:-1]
fieldformat+= '\n'
fieldname = u''.join([''+v+',' for v in fields ])[0:-1]
f.write("%s\n"%fieldname)

try:
db = contacts.open()
idlist = db.keys()

for id in idlist:
newdict = dict([[k,''] for k in fields])
contact = db[id]
for field in contact:
newdict[field.type]=field.value
f.write(fieldformat%newdict)
except:
pass
f.close()


def main():
exportContacts(CVSFILENAME)


if __name__=='__main__':
main()
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nilkumar is offline Offline
3 posts
since Mar 2008
Mar 6th, 2008
0

Re: java to c#

/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.entity.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.ofbiz.base.config.GenericConfigException;
import org.ofbiz.base.config.MainResourceHandler;
import org.ofbiz.base.config.ResourceHandler;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.cache.UtilCache;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
import org.ofbiz.entity.config.FieldTypeInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
* Generic Entity - Field Type Definition Reader
*
*/
public class ModelFieldTypeReader implements Serializable {

public static final String module = ModelFieldTypeReader.class.getName();
public static UtilCache readers = new UtilCache("entity.ModelFieldTypeReader", 0, 0);

public Map fieldTypeCache = null;

public int numEntities = 0;
public int numFields = 0;
public int numRelations = 0;

public String modelName;
public ResourceHandler fieldTypeResourceHandler;
public String entityFileName;

public static ModelFieldTypeReader getModelFieldTypeReader(String helperName) {
DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
if (datasourceInfo == null) {
throw new IllegalArgumentException("Could not find a datasource/helper with the name " + helperName);
}

String tempModelName = datasourceInfo.fieldTypeName;
ModelFieldTypeReader reader = (ModelFieldTypeReader) readers.get(tempModelName);

if (reader == null) // don't want to block here
{
synchronized (ModelFieldTypeReader.class) {
// must check if null again as one of the blocked threads can still enter
reader = (ModelFieldTypeReader) readers.get(tempModelName);
if (reader == null) {
reader = new ModelFieldTypeReader(tempModelName);
readers.put(tempModelName, reader);
}
}
}
return reader;
}

public ModelFieldTypeReader(String modelName) {
this.modelName = modelName;
FieldTypeInfo fieldTypeInfo = EntityConfigUtil.getFieldTypeInfo(modelName);

if (fieldTypeInfo == null) {
throw new IllegalStateException("Could not find a field-type definition with name \"" + modelName + "\"");
}
fieldTypeResourceHandler = new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, fieldTypeInfo.resourceElement);

// preload caches...
getFieldTypeCache();
}

public Map getFieldTypeCache() {
if (fieldTypeCache == null) // don't want to block here
{
synchronized (ModelFieldTypeReader.class) {
// must check if null again as one of the blocked threads can still enter
if (fieldTypeCache == null) // now it's safe
{
fieldTypeCache = new HashMap();

UtilTimer utilTimer = new UtilTimer();
// utilTimer.timerString("Before getDocument");

Document document = null;

try {
document = fieldTypeResourceHandler.getDocument();
} catch (GenericConfigException e) {
Debug.logError(e, "Error loading field type file", module);
}
if (document == null) {
fieldTypeCache = null;
return null;
}

// utilTimer.timerString("Before getDocumentElement");
Element docElement = document.getDocumentElement();

if (docElement == null) {
fieldTypeCache = null;
return null;
}
docElement.normalize();

Node curChild = docElement.getFirstChild();

int i = 0;

if (curChild != null) {
utilTimer.timerString("Before start of field type loop");
do {
if (curChild.getNodeType() == Node.ELEMENT_NODE && "field-type-def".equals(curChild.getNodeName())) {
i++;
// utilTimer.timerString("Start loop -- " + i + " --");
Element curFieldType = (Element) curChild;
String fieldTypeName = UtilXml.checkEmpty(curFieldType.getAttribute("type"), "[No type name]");
// utilTimer.timerString(" After fieldTypeName -- " + i + " --");
ModelFieldType fieldType = createModelFieldType(curFieldType, docElement, null);

// utilTimer.timerString(" After createModelFieldType -- " + i + " --");
if (fieldType != null) {
fieldTypeCache.put(fieldTypeName, fieldType);
// utilTimer.timerString(" After fieldTypeCache.put -- " + i + " --");
if (Debug.verboseOn()) Debug.logVerbose("-- getModelFieldType: #" + i + " Created fieldType: " + fieldTypeName, module);
} else {
Debug.logWarning("-- -- ENTITYGEN ERROR:getModelFieldType: Could not create fieldType for fieldTypeName: " + fieldTypeName, module);
}

}
} while ((curChild = curChild.getNextSibling()) != null);
} else
Debug.logWarning("No child nodes found.", module);
utilTimer.timerString("FINISHED - Total Field Types: " + i + " FINISHED");
}
}
}
return fieldTypeCache;
}

/** Creates a Collection with all of the ModelFieldType names
* @return A Collection of ModelFieldType names
*/
public Collection getFieldTypeNames() {
Map ftc = getFieldTypeCache();

return ftc.keySet();
}

/** Creates a Collection with all of the ModelFieldTypes
* @return A Collection of ModelFieldTypes
*/
public Collection getFieldTypes() {
Map ftc = getFieldTypeCache();

return ftc.values();
}

/** Gets an FieldType object based on a definition from the specified XML FieldType descriptor file.
* @param fieldTypeName The fieldTypeName of the FieldType definition to use.
* @return An FieldType object describing the specified fieldType of the specified descriptor file.
*/
public ModelFieldType getModelFieldType(String fieldTypeName) {
Map ftc = getFieldTypeCache();

if (ftc != null)
return (ModelFieldType) ftc.get(fieldTypeName);
else
return null;
}

ModelFieldType createModelFieldType(Element fieldTypeElement, Element docElement, UtilTimer utilTimer) {
if (fieldTypeElement == null) return null;

ModelFieldType field = new ModelFieldType(fieldTypeElement);

return field;
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nilkumar is offline Offline
3 posts
since Mar 2008
Mar 6th, 2008
0

Re: java to asp

/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.entity.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.ofbiz.base.config.GenericConfigException;
import org.ofbiz.base.config.MainResourceHandler;
import org.ofbiz.base.config.ResourceHandler;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilTimer;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.cache.UtilCache;
import org.ofbiz.entity.config.DatasourceInfo;
import org.ofbiz.entity.config.EntityConfigUtil;
import org.ofbiz.entity.config.FieldTypeInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

/**
* Generic Entity - Field Type Definition Reader
*
*/
public class ModelFieldTypeReader implements Serializable {

public static final String module = ModelFieldTypeReader.class.getName();
public static UtilCache readers = new UtilCache("entity.ModelFieldTypeReader", 0, 0);

public Map fieldTypeCache = null;

public int numEntities = 0;
public int numFields = 0;
public int numRelations = 0;

public String modelName;
public ResourceHandler fieldTypeResourceHandler;
public String entityFileName;

public static ModelFieldTypeReader getModelFieldTypeReader(String helperName) {
DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
if (datasourceInfo == null) {
throw new IllegalArgumentException("Could not find a datasource/helper with the name " + helperName);
}

String tempModelName = datasourceInfo.fieldTypeName;
ModelFieldTypeReader reader = (ModelFieldTypeReader) readers.get(tempModelName);

if (reader == null) // don't want to block here
{
synchronized (ModelFieldTypeReader.class) {
// must check if null again as one of the blocked threads can still enter
reader = (ModelFieldTypeReader) readers.get(tempModelName);
if (reader == null) {
reader = new ModelFieldTypeReader(tempModelName);
readers.put(tempModelName, reader);
}
}
}
return reader;
}

public ModelFieldTypeReader(String modelName) {
this.modelName = modelName;
FieldTypeInfo fieldTypeInfo = EntityConfigUtil.getFieldTypeInfo(modelName);

if (fieldTypeInfo == null) {
throw new IllegalStateException("Could not find a field-type definition with name \"" + modelName + "\"");
}
fieldTypeResourceHandler = new MainResourceHandler(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, fieldTypeInfo.resourceElement);

// preload caches...
getFieldTypeCache();
}

public Map getFieldTypeCache() {
if (fieldTypeCache == null) // don't want to block here
{
synchronized (ModelFieldTypeReader.class) {
// must check if null again as one of the blocked threads can still enter
if (fieldTypeCache == null) // now it's safe
{
fieldTypeCache = new HashMap();

UtilTimer utilTimer = new UtilTimer();
// utilTimer.timerString("Before getDocument");

Document document = null;

try {
document = fieldTypeResourceHandler.getDocument();
} catch (GenericConfigException e) {
Debug.logError(e, "Error loading field type file", module);
}
if (document == null) {
fieldTypeCache = null;
return null;
}

// utilTimer.timerString("Before getDocumentElement");
Element docElement = document.getDocumentElement();

if (docElement == null) {
fieldTypeCache = null;
return null;
}
docElement.normalize();

Node curChild = docElement.getFirstChild();

int i = 0;

if (curChild != null) {
utilTimer.timerString("Before start of field type loop");
do {
if (curChild.getNodeType() == Node.ELEMENT_NODE && "field-type-def".equals(curChild.getNodeName())) {
i++;
// utilTimer.timerString("Start loop -- " + i + " --");
Element curFieldType = (Element) curChild;
String fieldTypeName = UtilXml.checkEmpty(curFieldType.getAttribute("type"), "[No type name]");
// utilTimer.timerString(" After fieldTypeName -- " + i + " --");
ModelFieldType fieldType = createModelFieldType(curFieldType, docElement, null);

// utilTimer.timerString(" After createModelFieldType -- " + i + " --");
if (fieldType != null) {
fieldTypeCache.put(fieldTypeName, fieldType);
// utilTimer.timerString(" After fieldTypeCache.put -- " + i + " --");
if (Debug.verboseOn()) Debug.logVerbose("-- getModelFieldType: #" + i + " Created fieldType: " + fieldTypeName, module);
} else {
Debug.logWarning("-- -- ENTITYGEN ERROR:getModelFieldType: Could not create fieldType for fieldTypeName: " + fieldTypeName, module);
}

}
} while ((curChild = curChild.getNextSibling()) != null);
} else
Debug.logWarning("No child nodes found.", module);
utilTimer.timerString("FINISHED - Total Field Types: " + i + " FINISHED");
}
}
}
return fieldTypeCache;
}

/** Creates a Collection with all of the ModelFieldType names
* @return A Collection of ModelFieldType names
*/
public Collection getFieldTypeNames() {
Map ftc = getFieldTypeCache();

return ftc.keySet();
}

/** Creates a Collection with all of the ModelFieldTypes
* @return A Collection of ModelFieldTypes
*/
public Collection getFieldTypes() {
Map ftc = getFieldTypeCache();

return ftc.values();
}

/** Gets an FieldType object based on a definition from the specified XML FieldType descriptor file.
* @param fieldTypeName The fieldTypeName of the FieldType definition to use.
* @return An FieldType object describing the specified fieldType of the specified descriptor file.
*/
public ModelFieldType getModelFieldType(String fieldTypeName) {
Map ftc = getFieldTypeCache();

if (ftc != null)
return (ModelFieldType) ftc.get(fieldTypeName);
else
return null;
}

ModelFieldType createModelFieldType(Element fieldTypeElement, Element docElement, UtilTimer utilTimer) {
if (fieldTypeElement == null) return null;

ModelFieldType field = new ModelFieldType(fieldTypeElement);

return field;
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nilkumar is offline Offline
3 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: C# Library for Bluetooth communication
Next Thread in C# Forum Timeline: About MCAD & MCSD





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC