?

Log in

No account? Create an account
Инспекция кода. Всем выйти из сумрака)) [entries|archive|friends|userinfo]
Инспекция кода. Всем выйти из сумрака))

[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Kiev Java conference [Jan. 8th, 2011|09:13 pm]
Инспекция кода. Всем выйти из сумрака))

main_framer
Коллеги,

Мы хотим провести конференцию по Java в Киеве.
В данный момент мы выбираем интересные темы / докладчиков.
Draft списка тем я привожу в конце топика.

В связи с этим вопрос - есть желание / возможность выступить?
Можете предложить свои темы.

И ещё.
Можете порекомендовать кого-то из толковых и опытных ребят в качестве докладчиков?

Спасибо.



Темы (draft).

Read more...Collapse )
linkpost comment

Looking for a job. java team lead / system architect [Mar. 13th, 2010|12:38 pm]
Инспекция кода. Всем выйти из сумрака))

main_framer
Hi!

At the moment I am looking for a job of java team lead / system architect.
CV
http://www.chantingwolf.narod.ru/cv8en.doc
LinkedIN profile
http://www.linkedin.com/in/mykbova

-Mykola
linkpost comment

Новое ЖЖ сообщество / New LJ community. [Dec. 8th, 2008|12:27 am]
Инспекция кода. Всем выйти из сумрака))

main_framer
j2ee.
j2ee_ua
linkpost comment

Delphi + COM [Aug. 21st, 2007|06:43 pm]
Инспекция кода. Всем выйти из сумрака))
asusl
Доброго времени суток. Хочу  представить на суд уважаемой публики кусочек своей программы. Этот кусочек в принципе достаточно самостоятелен и живет у меня уже не в одной программе. Однако плотно инспектировать никто его не пытался. Написал 1 раз , отладил - работает - и не лазал туда больше )))
Задача была такая - реализовать позднее связывание. Готового ничего не нашел , признаться и искал не долго.
Решил написать сам. В процессе там еще и кэширование прикрутил к этому делу... повысило быстродействие заметно.
Сразу прошу прощение за отсутствие комментов.
Собсно вот:


unit uComContainer;

interface

Uses Classes,SysUtils,Windows,Variants,ComObj,ActiveX;

{$DEFINE CACHEPROPS}

Type

TCachedProperty = record
  PropName : string;
  PropValue : OleVariant;
end;

TCachedProperties = array of TCachedProperty;

TComContainer = class(TPersistent)
  private
    FDisp : IDispatch;
    FFailIfErr : Boolean;
    FComExc : TExcepInfo;
    FCache : TCachedProperties;
    FCacheProps : boolean;
    function FindDispatcher(Disp : IDispatch;var Name : String) : OleVariant;
    procedure InvokeHelper(Disp : IDispatch;DispId : TDispID;Flags : Word;
    Params : array of OleVariant;var Res : OleVariant);
    function GetComMemberDisp(Disp : IDispatch;Name : PWideChar) : TDispID;
    function AllocUString(AnsiLength : Cardinal) : pointer;
    procedure ReleaseUString(pStr : pointer);
    function GetFailIfComError : boolean;
    procedure SetFailIfComError(fice : boolean);
    Procedure RaiseComException(hr : HRESULT; ExcepInfo : PExcepInfo = nil);
    function IsLoaded : boolean;
    function _GetInnerProp(Name : String) : OleVariant;
    procedure _SetInnerProp(Name : String;Value : OleVariant);
    procedure SetCacheProps(Cp : boolean);
    function FindInCache(const Name : string;var Value : OleVariant) : Integer;
    procedure DoCacheProperty(const Name : string;const Value : OleVariant);
    function CreateClone : TComContainer;
  protected
    function GetComObject : OleVariant;virtual;
    function GetInnerProp(Name : String) : OleVariant;virtual;
    procedure SetInnerProp(Name : String;Value : OleVariant);virtual;
  public
    constructor Create; overload; virtual;
    constructor Create(DSP : IDispatch); overload; virtual;
    Property Loaded : boolean read IsLoaded;
    Property ComObject : OleVariant read GetComObject;
    procedure ClearCache;
    Property Prop[Name : String] : OleVariant read _GetInnerProp write _SetInnerProp;
    function Method(Name : string;Params : array of OleVariant) : OleVariant;virtual;
    Property FailIfComError : Boolean read GetFailIfComError write SetFailIfComError;
    Property CacheProps : boolean read FCacheProps write SetCacheProps;
    Property Clone : TComContainer read CreateClone;
    procedure Load(DSP : IDispatch);virtual;
    procedure ReleaseComObject;virtual;
    Destructor Destroy;override;
end;

implementation

function TComContainer.CreateClone : TComContainer;
begin
  Result := TComContainer.Create;
  Result.Load(FDisp);
end;

constructor TComContainer.Create;
begin
  Inherited;
  FDisp := nil;
  FFailIfErr := True;
  {$IFDEF CACHEPROPS}
    FCacheProps := true;
  {$ELSE}
    FCacheProps := false;
  {$ENDIF}
end;

function TComContainer.IsLoaded : boolean;
begin
  Result := FDisp <> nil;
end;

function TComContainer.GetComObject : OleVariant;
begin
  Result := FDisp;
end;

procedure TComContainer.ReleaseComObject;
begin

end;

procedure TComContainer.ClearCache;
begin
  SetLength(FCache,0);
end;

function TComContainer._GetInnerProp(Name : String) : OleVariant;
begin
  If FCAcheProps then
  begin
    if FindInCache(Name,Result) < 0 then
    begin
      Result := GetInnerProp(Name);
      DoCacheProperty(Name,Result);
    end;
  end
  else
    Result := GetInnerProp(Name);
end;

procedure TComContainer._SetInnerProp(Name : String;Value : OleVariant);
var CInd : Integer;
    OldValue : OleVariant;
begin
  SetInnerProp(Name,Value);
  If FCAcheProps then
  begin
    CInd := FindInCache(Name,OldValue);
    if CInd >= 0 then
      FCache[CInd].PropValue := Value;
  end
end;

function TComContainer.FindInCache(const Name : string;var Value : OleVariant) : Integer;
var i : Integer;
begin
  result := -1;
  for i := 0 to Length(FCache) - 1 do
    if FCache[i].PropName = Name then
    begin
      Value := FCache[i].PropValue;
      Result := i;
      exit;
    end;
end;

procedure TComContainer.DoCacheProperty(const Name : string;const Value : OleVariant);
begin
  SetLength(FCache,Length(FCache)+1);
  FCache[Length(FCache)-1].PropName := Name;
  FCache[Length(FCache)-1].PropValue := Value;
end;

procedure TComContainer.SetCacheProps(Cp : boolean);
begin
  if FCacheProps = cp then exit;
  FCacheProps := cp;
  if not FCacheProps then SetLength(FCache,0);
end;

function TComContainer.GetInnerProp(Name : String) : OleVariant;
var Dispatcher : IDispatch;
  DispId : TDispID;
  PName : PWideChar;
begin
  Dispatcher := FindDispatcher(FDisp,Name);
  PName := AllocUString(Length(Name));
  StringToWideChar(Name,PName,(Length(Name)+1)*2);
  DispId := GetComMemberDisp(Dispatcher,PName);
  ReleaseUString(PName);
  InvokeHelper(Dispatcher,DispId,DISPATCH_PROPERTYGET,[],Result);
end;

procedure TComContainer.SetInnerProp(Name : String;Value : OleVariant);
var Dispatcher : IDispatch;
  DispId : TDispID;
  PName : PWideChar;
  res : OleVariant;
begin
  Dispatcher := FindDispatcher(FDisp,Name);
  PName := AllocUString(Length(Name));
  StringToWideChar(Name,PName,(Length(Name)+1)*2);
  DispId := GetComMemberDisp(Dispatcher,PName);
  ReleaseUString(PName);
  InvokeHelper(Dispatcher,DispId,DISPATCH_PROPERTYPUT,[Value],res);
end;

function TComContainer.GetFailIfComError : boolean;
begin
  Result := FFailIfErr;
end;

procedure TComContainer.SetFailIfComError(fice : boolean);
begin
  FFailIfErr := fice;
end;

function TComContainer.AllocUString(AnsiLength : Cardinal) : pointer;
begin
  GetMem(Result,(AnsiLength+1)*2);
end;

procedure TComContainer.ReleaseUString(pStr : pointer);
begin
  FreeMem(pStr);
end;

Procedure TComContainer.RaiseComException(hr : HRESULT; ExcepInfo : PExcepInfo = nil);
begin
  case hr of
    S_OK : raise Exception.Create('Operation succeded, but method RaiseComException has been called.');
    E_OUTOFMEMORY : raise Exception.Create('Out of memory.');
    DISP_E_UNKNOWNNAME : raise Exception.Create('One or more of the names were not known.');
    DISP_E_UNKNOWNLCID : raise Exception.Create('The locale identifier (LCID) was not recognized.');
    DISP_E_BADPARAMCOUNT : raise Exception.Create('The number of elements provided to DISPPARAMS is different from the number of arguments accepted by the method or property.');
    DISP_E_BADVARTYPE : raise Exception.Create('One of the arguments in rgvarg is not a valid variant type.');
//    DISP_E_EXCEPTION : raise Exception.Create(FComExc.bstrDescription);
    DISP_E_EXCEPTION : if ExcepInfo <> nil then raise Exception.Create(ExcepInfo.bstrDescription)
                       else raise Exception.Create(FComExc.bstrDescription);
    DISP_E_MEMBERNOTFOUND : raise Exception.Create('The requested member does not exist, or the call to Invoke tried to set the value of a read-only property.');
    DISP_E_NONAMEDARGS : raise Exception.Create('This implementation of IDispatch does not support named arguments.');
    DISP_E_OVERFLOW : raise Exception.Create('One of the arguments in rgvarg could not be coerced to the specified type.');
    DISP_E_PARAMNOTFOUND : raise Exception.Create('One of the parameter DISPIDs does not correspond to a parameter on the method. In this case, puArgErr should be set to the first argument that contains the error.');
    DISP_E_TYPEMISMATCH : raise Exception.Create('One or more of the arguments could not be coerced. The index within rgvarg of the first parameter with the incorrect type is returned in the puArgErr parameter.');
    DISP_E_UNKNOWNINTERFACE : raise Exception.Create('The interface identifier passed in riid is not IID_NULL.');
    DISP_E_PARAMNOTOPTIONAL : raise Exception.Create('A required parameter was omitted.');
  end;
end;

function TComContainer.GetComMemberDisp(Disp : IDispatch;Name : PWideChar) : TDispID;
var hr : HRESULT;
begin
  If Not Loaded then
    Raise Exception.Create('COM Container empty!');
  if Disp = nil then exit;
  hr := Disp.GetIDsOfNames(GUID_NULL,@Name,1,LOCALE_SYSTEM_DEFAULT,@Result);
  if hr <> S_OK then
    If FFailIfErr then RaiseComException(hr);
end;

procedure TComContainer.Load(DSP : IDispatch);
begin
  If Loaded then
    ReleaseComObject;
  if DSP = nil then Raise Exception.Create('Attempt to load NULL interface!');
  FDisp := DSP;
end;

Function TComContainer.Method(Name : string;Params : array of OleVariant) : OleVariant;
var Dispatcher : IDispatch;
  DispId : TDispID;
  PName : PWideChar;
begin
  Dispatcher := FindDispatcher(FDisp,Name);
try
  PName := AllocUString(Length(Name));
  StringToWideChar(Name,PName,(Length(Name)+1)*2);
  DispId := GetComMemberDisp(Dispatcher,PName);
finally
  ReleaseUString(PName);
end;
  InvokeHelper(Dispatcher,DispId,DISPATCH_METHOD,Params,Result);
end;

function TComContainer.FindDispatcher(Disp : IDispatch;var Name : String) : OleVariant;
var NextName : string;
  SepPos : integer;
  PName : PWideChar;
  DispId : TDispID;
begin
  SepPos := Pos ('.',Name);
  if SepPos = 0 then Result := Disp
  else
  begin
    NextName := Copy(Name,1,SepPos-1);
   try
     PName := AllocUString(Length(NextName));
     StringToWideChar(NextName,PName,(Length(NextName)+1)*2);
     DispId := GetComMemberDisp(Disp,StringToWideChar(NextName,PName,(Length(Name)+1)*2));
   finally
     ReleaseUString(PName);
   end;
    InvokeHelper(Disp,DispId,DISPATCH_PROPERTYGET,[],Result);
    Name := copy(Name,SepPos+1,Length(Name)-2);
    if not VarIsNull(Result) then
      Result := FindDispatcher(Result,Name);
  end;
end;

procedure TComContainer.InvokeHelper(Disp : IDispatch;DispId : TDispID;Flags : Word;
Params : array of OleVariant;var Res : OleVariant);
var hr : HRESULT;
  aDispParams : TDispParams;
  aDispId     : array of TDispId;
  aEI         : TExcepInfo;
  iError      : UINT;
  ParStr : String;
  i : Integer;
begin
  if Disp = nil then exit;
  FillChar(aDispParams, SizeOf (aDispParams), 0);
  if (Flags = DISPATCH_PROPERTYPUT) or (Flags = DISPATCH_METHOD) then
  begin
    with aDispParams do begin
      cArgs := Length(Params);
      rgvarg := @Params;
      if Flags = DISPATCH_PROPERTYPUT then
      begin
        cNamedArgs := 1;
        SetLength(aDispId,1);
        aDispId[0] := DISPID_PROPERTYPUT;
        rgdispidNamedArgs := @aDispId;
      end;
    end;
  end;
  hr := Disp.Invoke(DispId,GUID_NULL,LOCALE_SYSTEM_DEFAULT,Flags,aDispParams,@Res,@aEI,@iError);
  if Flags = DISPATCH_PROPERTYPUT then
    SetLength(aDispId,0);
  if hr <> S_OK then
    If FFailIfErr then RaiseComException(hr, @aEI)
end;

Destructor TComContainer.Destroy;
begin
  If Loaded then
    ReleaseComObject;
  SetLength(FCache,0);
  inherited;
end;

constructor TComContainer.Create(DSP: IDispatch);
begin
  Create;
  Load(DSP);
end;

initialization

//

finalization

//

end.
linkpost comment

navigation
[ viewing | most recent entries ]