• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1004
  • Last Modified:

How to call equivalent of Server.CreateObject from Java

Hi,
 I have an ASP page that creates an instance of an applications mapserver object, and then calls some of its functions. It's written in ASP, and I'm wondering whether I could do the same thing from java?
var mapserver;
mapserver = Server.CreateObject("Manifold.MapServer");
mapserver.Create(Server.MapPath("config.txt"), parameter("state", ""), Server);
 
// handle OGC WMS command
var wms = mapserver.CreateOgcWmsDriver();
if (wms.Handle(Request.QueryString, "http://" + Request.ServerVariables("SERVER_NAME") + Request.ServerVariables("URL"))) {
	Response.ContentType = wms.ResultContentType;
	if (wms.ResultContentType.indexOf("image/") >= 0)
		Response.BinaryWrite(wms.Result);
	else
		Response.Write(wms.Result);
 
	// release mapserver object
	mapserver = null;
 
	Response.End();
}

Open in new window

0
chrismarx
Asked:
chrismarx
  • 5
  • 5
  • 3
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
It depends on the availability of the objects you are using in ASP as API's for Java; however, to answer your question, the equivalent in Java is to instantiate an object of the class like Manifold.MapServer.  It is the same you would do in .NET.

e.g.

VB.NET ==> Dim mapserver As New Manifold.MapServer()
C#.NET ==> Manifold.MapServer mapserver = new Manifold.MapServer();
Java ==> Manifold.MapServer mapserver = new Manifold.MapServer();

Again this would need the real class/package names for API.  For example, Java's convention is to have lowercase package names versus .NET's upper/camel case style namespaces.  People do things differently, but think in general you may see something like this for same package in java: com.manifold.MapServer mapserver = new com.manifold.MapServer().

Hopefully that helps.
0
 
CEHJCommented:
If 'from Java' == from JavaScript, then yes, otherwise you would need to have a Java/ActiveX bridge
0
 
Kevin CrossChief Technology OfficerCommented:
CEHJ is correct is you were meaning literally to use the ActiveX component Manifold.MapServer.  I apologize -- for some reason thought you were asking about the concept of creating objects but CEHJ's response makes more sense if like he said "Java" == JavaScript.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
chrismarxAuthor Commented:
no, not from javascript, from a java controller. i've never tried to access the functions as you described

com.manifold.MapServer mapserver = new com.manifold.MapServer().

where does one go to see these packages?
0
 
Kevin CrossChief Technology OfficerCommented:
I was showing generically how instantiating objects work in Java.  Thought that was the question.  You will need to see if there is an API in Java for the class you are using in ASP and use that class as shown.  That was my fault that I realized after CEHJ posted.
0
 
chrismarxAuthor Commented:
no problems, yeah i've used "new" many times. so there is no api in java, there is only a .net api, its a very microsoft centric product...
0
 
Kevin CrossChief Technology OfficerCommented:
There may be similar API's, so don't get us wrong.  Just not going to be that exact ActiveX component.  

For example found this:
http://mapserver.gis.umn.edu/docs/howto/javamapscript
0
 
chrismarxAuthor Commented:
yeah, actually, i need to use this software

http://www.manifold.net/index.shtml

here are some posts that describe working with manifold from visual studio, which basically describes what i need to do, but from java

http://www.manipedia.eu/index.php?title=COM_/_External_Programming


0
 
chrismarxAuthor Commented:
so i made some progress...

i tried to run the first code snippet, (saved as .vbs file) but it only opened up a cscript command window, and didn't do anything.

then i tried the second snippet from pythonWin and that worked.
so now i'm wondering what it will take to do these examples in java

'VBScript
 
Set app = CreateObject("Manifold.Application")
 
Set doc = app.NewDocument("c:\data\test.map", False)
 
MsgBox doc.ComponentSet.Count
 
 
 
#######
from win32com.client import constants, Dispatch, CastTo
 
def setUp(mapfile):
    app = Dispatch("Manifold.Application")
    doc = app.DocumentSet.Open(mapfile,False)
    cset = doc.ComponentSet
    return app,doc,cset
 
 
#Set Up Your Global Variables and Your Map File --- Setting ReadOnly To False
print 'Open Map'
app,doc,cset = setUp("C:\RN.map")
print 'Create Query'
Q = doc.NewQuery('TempQ')
Q.Text="""
        Select * from [AAA]
 
 
 
        """
Q.Run
 
QT = CastTo(Q.Table,"ITable")
print QT.RecordSet.Count
#QTR =
QTR = CastTo(QT.RecordSet,"IRecordSet")
 
for each in QTR:
    each = CastTo(each,"IRecord")
    print each.DataByIndex(0)
# Remove Query
cset.Remove('TempQ')
 
 
doc.Save()      
doc.Close()
app.Quit()
doc==None
app==None
cset==None

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
Have a meeting now, but will take a look...
0
 
CEHJCommented:
0
 
chrismarxAuthor Commented:
i got my vbscript examples working, just need to download the latest version of the windows script host. the bridge looks good, i will look into that!
0
 
CEHJCommented:
:-)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now