Archive for June, 2008

from the stone

picasso tribute

PicassoVollard

Associate your program with file extension

article source : http://www.delphi3000.com/articles/article_525.asp?SK=
author : Igor Siticov

For creating file associations you should make some registry changes and inform Windows explorer about your changes.

For launching your program as default for all unregistered file types just associate it for “*” file type.

The following unit includes realization of function for creating file association.
See comments in source for details.

  1.  
  2. unit utils;
  3.  
  4. interface
  5. uses Registry, ShlObj, SysUtils, Windows;
  6.  
  7. procedure RegisterFileType(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false);
  8.  
  9. implementation
  10.  
  11. procedure RegisterFileType(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false);
  12. var
  13.    Reg: TRegistry;
  14. begin
  15.   Reg := TRegistry.Create;
  16.   try
  17.     Reg.RootKey := HKEY_CLASSES_ROOT;
  18.     Reg.OpenKey(cMyExt, True);
  19.     // Write my file type to it.
  20.     // This adds HKEY_CLASSES_ROOT\.abc\(Default) = ‘Project1.FileType’
  21.     Reg.WriteString(, cMyFileType);
  22.     Reg.CloseKey;
  23.     // Now create an association for that file type
  24.     Reg.OpenKey(cMyFileType, True);
  25.     // This adds HKEY_CLASSES_ROOT\Project1.FileType\(Default)
  26.     //   = ‘Project1 File’
  27.     // This is what you see in the file type description for
  28.     // the a file’s properties.
  29.     Reg.WriteString(, cMyDescription);
  30.     Reg.CloseKey;    // Now write the default icon for my file type
  31.     // This adds HKEY_CLASSES_ROOT\Project1.FileType\DefaultIcon
  32.     //  \(Default) = ‘Application Dir\Project1.exe,0′
  33.     Reg.OpenKey(cMyFileType + ‘\DefaultIcon’, True);
  34.     Reg.WriteString(, ExeName + ‘,’ + IntToStr(IcoIndex));
  35.     Reg.CloseKey;
  36.     // Now write the open action in explorer
  37.     Reg.OpenKey(cMyFileType + ‘\Shell\Open’, True);
  38.     Reg.WriteString(, ‘&Open’);
  39.     Reg.CloseKey;
  40.     // Write what application to open it with
  41.     // This adds HKEY_CLASSES_ROOT\Project1.FileType\Shell\Open\Command
  42.     //  (Default) = ‘"Application Dir\Project1.exe" "%1"’
  43.     // Your application must scan the command line parameters
  44.     // to see what file was passed to it.
  45.     Reg.OpenKey(cMyFileType + ‘\Shell\Open\Command’, True);
  46.     Reg.WriteString(, ‘"’ + ExeName + ‘" "%1"’);
  47.     Reg.CloseKey;
  48.     // Finally, we want the Windows Explorer to realize we added
  49.     // our file type by using the SHChangeNotify API.
  50.     if DoUpdate then SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
  51.   finally
  52.     Reg.Free;
  53.   end;
  54. end;
  55.  
  56. end.
  57.  

JNI Interface used to integrate static C++/Delphi Library in Java

Today i found some great post to make an integration between JAVA and static library genetated with C++ using JNI.
post links :

  • http://forum.java.sun.com/thread.jspa?threadID=786600&messageID=4484880

  • http://www.inonit.com/cygwin/jni/helloWorld/
  • stay tuned
    ivan…

    Deploying web service with Java and Axis

    In this article we see how can we deploy a web service, you need to have apache, tomcat and axis up and running.

    To publish a simple webservice:
    Create a simple text file, for example “Somma.jws” like this

    1. public class Somma {
    2. public int somma(int a, int b) {
    3. return a+b;
    4. }
    5. }

    Put this file in the axis directory, for example: /usr/local/apache-tomcat-6.0.13/webapps/axis
    the web service is already available at: http://localhost:8080/axis/Somma.jws
    the WSDL: http://localhost:8080/axis/Somma.jws?wsdl
    direct invocation via query string: http://localhost:8080/axis/Somma.jws?method=somma&a=2&b=3
    This is a very interesting feature, you can call the web service via simple web request, for example via javascript, without the complicated stuff needed for invoking a web service .

    The jws web service is simple and fast, but they support only standard type String, int and so on.

    For a more complex web service you have to deploy it from the java source code, and a wsdd (Web Service Deployment Descriptor) text file:

    Example:

    1. package com.server;
    2. public class Company {
    3. public int companyID;
    4. public String companyName;
    5. public String[ ] employeeNames;
    6. }
    1. package com.server;
    2. public class CompanyService{
    3.  
    4. /**
    5. * @return company object
    6. */
    7. public Company getCompanyData(){
    8. Company company = new Company();
    9. String [] employeeNames = new String[] { "Balaji", "LSMS" , "LLQ" };
    10. company.companyID = 2311;
    11. company.companyName = "Test";
    12. company.employeeNames = employeeNames;
    13. return company;
    14. }
    15. }
    1. <deployment xmlns="http://xml.apache.org/axis/wsdd/">
    2. xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
    3. xmlns:myNS="http://www.synaptica.info" >
    4. <service name="CompanyRepository" provider="java:RPC"></service></deployment>
    5. <parameter name="className" value="com.server.CompanyService"></parameter>
    6. <parameter name="allowedMethods" value="getCompanyData"></parameter>
    7. <parameter name="wsdlTargetNamespace" value="CompanyService"></parameter> <beanmapping qname="myNS:Company" languagespecifictype="java:com.server.Company"></beanmapping></deployment>

    Run (you can do it via the eclipse run dialog)
    java org.apache.axis.client.AdminClient deployCompanyWS.wsdd
    You have deployed your WS.
    try it http://localhost:8080/axis/services/CompanyRepository?method=getCompanyData
    note how the Company class is serialized through xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    3. <soapenv:Body> <getCompanyDataResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    4. <getCompanyDataReturn href="#id0"/> </getCompanyDataResponse>
    5. <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:Company" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.synaptica.info"> <companyID href="#id1"/>
    6. <companyName xsi:type="soapenc:string">Test</companyName>
    7. <employeeNames xsi:type="soapenc:string">Balaji</employeeNames> <employeeNames xsi:type="soapenc:string">LSMS</employeeNames>
    8. <employeeNames xsi:type="soapenc:string">LLQ</employeeNames> </multiRef><multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">2311 </multiRef> </soapenv:Body>
    9. </soapenv:Envelope>

    to undeploy

    1. <undeployment>
    2.     xmlns="http://xml.apache.org/axis/wsdd/">
    3. <!– Services from SommaService WSDL service –>
    4. <service name="CompanyRepository">
    5. </service></undeployment>

    java org.apache.axis.client.AdminClient undeploy.wsdd

    To create Java Helper class to call the web service just created:
    java org.apache.axis.wsdl.WSDL2Java http://localhost:8080/axis/services/CompanyRepository?wsdl