Is this is best practise

Hi,
I have a class called CustomDocument , to which i pass a URL, this will inturn call two methods getW3cDocument and splitDocumentIntoFields, these two methods parse the document and populate the hash map accordingly with necessary values.
I was suggested that that this way of calling a constructor and creating a document object was not good practice, in case there is a parsing error or if some exception occurs , then the constructor might throw an exception half way through constructing the object.
No site that i reffered to gave any such specification with respect to constructors.
Are constructors only to initialize variables. What if in such cases where i want all my fields (hashmap) populated with values , i.e as soon as i create an object , the field contents should be present in the hashmap.
1. Can anyone tell me if this confirms to java best practices?
2. Is it right if constuctors call methods, that will do some processing to initialize valus to say hashmaps in my case?
3. Shouldnt constructors throw exceptions? (half way through creating an object lets say)?
public class CustomDocument
private java.net.URL _url;
private org.w3c.dom.Document _w3cdoc;
private java.util.HashMap<String, Field> _fieldContents;
public CustomDocument(URL url) {
    _url = url;
  // Initializing the field contents
    _fieldContents = new HashMap<String, Field>();
//Get the dom object
    _w3cdoc = getW3cDocument(_url);
//This method will read through the dom object and extract
//information and populate the hashmap _fieldContents
    splitDocumentIntoFields(_w3cdoc);
}Thanks.

2. Is it right if constuctors call methods, that will
do some processing to initialize valus to say
hashmaps in my case?It's fine for a ctor to call methods, but you have to be careful about calling non-final methods on the object being initialized.
import java.util.*;
public class CtorNonFinalMethod {
    public static void main(String[] args) throws Exception {
        new Child();
class Parent {
    int ii;
    Parent() {
        System.out.println("entering parent ctor");
        init();
        System.out.println("leaving parent ctor");
    void init() {
        System.out.println("entering parent init");
        ii = 123;
        System.out.println("leaving parent init");
class Child extends Parent {
    List<String> list = new ArrayList<String>();
    void init() {
        System.out.println("entering child init, list = " + list);
        list.add("abc");
        System.out.println("leaving child init, list = " + list);
entering parent ctor
entering child init, list = null
Exception in thread "main" java.lang.NullPointerException
     at Child.init(CtorNonFinalMethod.java:30)
     at Parent.<init>(CtorNonFinalMethod.java:14)
     at Child.<init>(CtorNonFinalMethod.java:25)
     at CtorNonFinalMethod.main(CtorNonFinalMethod.java:5)

Similar Messages

  • What is the best practise to provide a text file for a Java class in a OSGi bundle in CQ?

    This is probably a very basic question so please bear with me.
    What is the best way to provide a .txt file to be read by a Java class in a OSGi bundle in CQ 5.5?
    I have been able to read a file called "test.txt" that I put in a structure like this /src/resources/<any-sub-folder>/test.txt  from my java class  at /src/main/java/com/test/mytest/Test.java using the bundle's getResource and getEntry calls but I was not able to use the context.getDataFile. How is this getDataFile method call to be used?
    And what if I want to read the file located in another bundle, is it possible? or can I add the file to some repository and then access it - but I am not clear how to do this.
    And I would also like to know what is the best practise if I need to provide a large  data set in a flat file to be read by a Java class in CQ5.
    Please provide detailed steps or point me to a how to guide or other helpful resources as I am a novice.
    Thank you in advance for your time and help.
    VS

    As you can read in the OSGi Core specification (section 4.5.2), the getDataFile() method is to read/write a file in the bundle's private persistent area. It cannot be used to read files contained in the bundle. The issue Sham mentions refers to a version of Felix which is not used in CQ.
    The methods you mentioned (getResource and getEntry) are appropriate for reading files contained in a bundle.
    Reading a file from the repository is done using the JCR API. You can see a blueprint for how to do this by looking at the readFile method in http://svn.apache.org/repos/asf/jackrabbit/tags/2.4.0/jackrabbit-jcr-commons/src/main/java /org/apache/jackrabbit/commons/JcrUtils.java. Unfortunately, this method is not currently usable as it was declared incorrectly (should be a static method, but is an instance method).
    Regards,
    Justin

  • Advice or best practise information about 1 or 2 clients in SAP R/3 DEV

    I'm searching for advice or best practise information about clients in a SAP R/3 development system.
    Reason for this is that we are up to refresh our SAP R/3 development system and up to now we have two clients on it:
    -     One customizing/development client without master data, transaction data et cetera
    -     One local test client with master data, transaction data and so on
    One of our developers suggested to only have one client on development, where we could customize, program and test. So that client would be with master data, transaction data et cetera.
    What would be your advice or what would be best practise for the development system: 1 client (with data) or 2 clients (one clean customizing and one with data). And what are the most important reasons to do it so.
    Maybe there is already some good (SAP) information about this specific subject, but up to now I havenu2019t found it yet.

    Maybe I've asked my question too broad. I'll try to narrow it down.
    Up to now we always had two clients on our SAP R/3 development system:
    - Client 200 - Customizing/development only. No other data in this client
    - Client 400 - Local test client with master data and transaction data. New customizing is copied from client 200 to test
    The reason for having those two clients are:
    - It feels someway good to have a customizing-only client
    - We've always done this before
    A developer suggested to only have one client in our SAP R/3 development system for the following reason:
    - You'll never need to copy the customizing (tr.SCC1) first to be able to test it
    - You can work in one client and don't need to login in the other client to test it (for example: ABAP reports)
    - For customizing of easy setting (for example producthiërarchie, as we don't test it everytime in client 400) it is possible to forget copying it into client 400 (test client). With one client, you can not forget it
    The reasons of this developer seems very valid and up to now we haven't found a convincing/compelling reason to make a good choice for one or two clients.
    Please, try to convince us with good reasons to choose for one or two clients.

  • ECC 5.0 and BO without BW/BI Integration Best Practise

    Hi,
    I know that SAP can connect with BO system using RapidMart (replacing data warehouse BW/BI). Is this best practise?Because when i see the BI Platform RoadMap,I conclude that BI and BO will be integrate into one product, and i'm afraid to invest right now because in the future it seems we need to implement the BW system to make this BI system optimal.
    My company want to use BO without implement BW system right now. SAP system that we use right now is ECC 5.0 and my company only upgrade it to next version when version 5.0 not supported again.Thank you.
    Cheers,
    Satria

    Hi Satria,
    the answer depends a little bit on what the requirement is.
    RapidMarts are an option to implement a data mart solution on top of an ERP solution. On top of the Rapid Marts you can then use the BusinessObjects tools without hitting the OLTP system directly.
    Ingo

  • BEST PRACTISE on users deletions HR/SU01

    Hi
    we use CUA/SSO.
    The records are fed from HR records and sent to Active Directory (AD) 
    AD brings backs the records and creates/changes users in SU01
    A function module populates the CVR (timesheet) parameter dependent on whether you are an employee or a contractor 
    Occasionally, our HR department request records to be deleted from the SAP Support team - for example if the employee or contractor hasn't in fact joined the company.
    Until some time ago, the deletion was causing problems because:
    a) the record does not get deleted in AD and there is  no way to send the deletion across after
    b) when AD tries to reprocess that specific record, LDAP connector will not find it as HR record so what happens in SU01 for some reasons, the VALID from field gets wiped out and the CVR parameter for Timesheet also...
    We have changed the process for the deletion however, I would like to ask if you know what is the best practise for this?? HR want to delete the record so it can be re-utilised
    I cannot delete those records from UMR unless I am 100% sure they have never used the system (will have to check that)
    I hope I have provided enough info on what the issue is..
    Thank you
    Nadia

    Best practice is not to delete.
    > HR want to delete the record so it can be re-utilised
    So many people with the same name? Perhaps a suffix of 2 numbers when the ID naming convention produces a clash. Besides, do your AD admins not want unique names in the AD as well?
    E.g. (just an imperfect example)
    MUSTERMA = Alfred MUSTERMan
    MUSTERMM = Manfred MUSTERMan
    MUSTER01 = Mechtilde MUSTERMuller
    > I cannot delete those records from UMR unless I am 100% sure they have never used the system (will have to check that)
    Surest way is to determine that they have never logged on before. But that does not exclude that records might exist for them, which may eventually do a "user existence check" to be read. One such example is the Security Audit Log, e.g. there may have been failed login attempts.
    Good luck,
    Julius

  • Best practise for SAP users who leave the company

    Hi
    Could anyone reccommend a best practise document or give advice on how to deal with SAP user ID's when employee's/contractors/consultants leave? I am the basis admin just starting an SAP implementation and we have no dedicated authorisation team at the moment, so I have been asked to look into this :
    Currently we set the validity date in SU01 to the termination date.
    We chack there are no background jobs scheduled under that user id, if there are, we change the job owner to a valid user (we try to run all background jobs under an admin account).
    We do not delete the user as from an audit point of view I believe it restricts information you can report on and there are implications on change documents etc, so best to lock it with validity dates.
    Can anyone advise further?
    We are running SAP ECC 5.0 on Windows 2003 64 Bit/MS SQL 2000.
    Thanks for any help.

    Hi,
    Different people will tell you different versions of what they believe is best practice, but in my opinion you are already doing reasonably well.
    What I prefer is
    1. Lock ID & set validity date.
    2. Assign user to user group LEAVER or EXPIRED or something similar (helps with reporting) out of SUIM/S_BCE* reports.
    3. Delete role assignment (should you need it, the role assignment will be in the change history docs anyway).
    4. Check background jobs & act accordingly.
    For ease of getting info I prefer not to delete the ID though plenty of people do.

  • BI 7.0 Best practise

    hi  all,
    I need a the best practise of BI 7.0 ?(latest verison). could anybody help out.
    currently i have SAP Best Practices for Business Intelligence V1.30(2009).
    Thanks
    Ashok

    Hi CMS,
    Thanks for replying.
    Actually, this is the latest version.
    http://help.sap.com/bp_biv270/index.htm ( BI 7.0 Best practices version 2)
    The link you provided was BW 3.5 version Best Practices version 3.
    That's a bit weird naming convention from SAP
    There's also a way that you can get this on a DVD or download it rather than access each link on help.sap.com
    And i couldn't download it because i don't have download rights for my S-userid.
    Thanks
    Br,
    Ray

  • Best practise to feed an infoobject which depend on 0MATERIAL ?

    Hi experts,
    I'm a newbie on SDN and SAP BW. I have a question that could appear basic for you.
    I have to add a new infoobject "Article Typology" in a BW query. I will call it ZTYPOLOGY.
    This infoobject will contains 3 values which will depend on the description of 0MATERIAL (field /BI0/TMATERIAL-TXTMD) :
    If /BI0/TMATERIAL-TXTMD contains 'MDD', ZTYPOLOGY have to return "MDD"
    Elseif   /BI0/TMATERIAL-TXTMD contains '#', ZTYPOLOGY have to return "Import"
            else ZTYPOLOGY have to return "Other".
    I thought to create ZTYPOLOGY as an attribute of the masterdata 0MATERIAL, and feed it by an ABAP routine in the Update Rule which come from 0MATERIAL_ATTR. Is it a good idea ?
    If no, could you advise me about the best practise ?
    Don't hesitate if you need more information to understand my request.
    Thanks a lot.
    Tempka

    Hi,
    First check the source of your query, and see how do you want to see the Typology data in the report, i.e. Always updated data with current master data or the data at the time of transaction.
    For e.g. If you add your Infoobject as navigation attribute then you will always see only current master data. And if you add it in your Infocube or DSO etc. then the value will be static and it will show the value which was loaded historically.
    Once you finalize your approach you can simply create field routine and load your data.
    Regards,
    Durgesh.

  • Best practise to versioning Web Service WCF

    I've a web service SOAP developed with WCF, there is a best practise to versioning it? when I change the contract I don't want to update all the client's referiments but I want simply publish a new version that coexists with the old.
    STUDY-CASE: I've a web service with one endpoint, all clients point to it, soon I will have to change the contract and I search a way to avoid that all clients crash. I know two ways to avoid this:
    publish the web service with the new contract in another server
    create a new file svc with the new contract
    there are other ways?

    It depends on many things such as what changes you are going to make, what platform your clients are built on, what's your change tracking policy, etc.
    For example if you just want to add a new property to a data contract or a new operation to a service contract it's safe to add it to your current implementation as long as the clients are version tolerant (DataContractSerializer is version tolerant) and it
    complies with your change tracking policy. However you would better stick to strict versioning strategy which requires creating a new contract and exposing it with a new endpoint in case the changes are more serious.
    I suggested reading these articles:
    Versioning Strategies
    Best Practices: Data Contract Versioning
    This should help you to choose the right version strategy and provide your with the best practices to follow.

  • SAP Best Practises - Installation

    Hello All,
    I had installed SAP best Practises base line package SAP BP-ERP 617V6 in my system a couple of weeks back. But now when I am trying to activate the Best practises it is asking for the solution scope files and the installation text files. But when I am checking on Service market place , it seems SAP has with drawn the files for 617-V6 and has updated them with the latest files of 617-V7.
    Now without these files I cannot proceed any further. And I have already activated the Business sets and Business Enterprise Functions in Client 000 and created a new client from 000.
    In this regards can anyone advise what will be the best way forward. Can I upgrade my BP version BP-ERP 617-V7 now and proceed. Are there any special steps that I need to do for the BC sets which are already activated. I am guessing I will need to a client copy once again.
    I also went through SAP Note 1301301 , Point IV , which talks about the upgrade of SAP BP package but it lacks clarity on the above points.
    I have also raised a Customer message on this but will really appreciate your views in this regards.
    Thanks
    S

    Hello Surajit Das,
    In http://service.sap.com/swdc have you tried looking in Archive Area ?
    SAP will generally hold the previous versions of software and components in the archive area for some time.
    Regards,
    Siddhesh

  • Best Practises for Email Addresses?

    Hi Guys,
    Are there any best practise guides / documents / etc. for configuring user's E-mail addresses? We have a large turnaround of users and obviously sometimes they have the same name as previous/current employees (we
    do not delete any old accounts / mailboxes.) My question is whether or not it is OK to use numbers in an email address (i.e. [email protected])?
    Thanks
    Stephen

    Hi,
    It's OK to use numbers in an email address.
    The format of email addresses is local-part@domain where the local-part may be up to 64 characters long and the domain name may have a maximum of 253 characters.
    The local-part of the email address may use any of these ASCII characters RFC 5322
    Uppercase and lowercase English letters (a–z, A–Z) (ASCII: 65-90, 97-122)
    Digits 0 to 9 (ASCII: 48-57)
    Characters !#$%&'*+-/=?^_`{|}~ (ASCII: 33, 35-39, 42, 43, 45, 47, 61, 63, 94-96, 123-126)
    Character . (dot, period, full stop) (ASCII: 46) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively (e.g. John..[email protected] is not allowed.).
    Special characters are allowed with restrictions. They are:
           Space and "(),:;<>@[\] (ASCII: 32, 34, 40, 41, 44, 58, 59, 60, 62, 64, 91-93)
           The restrictions for special characters are that they must only be used when contained between quotation marks, and that 3 of them (The space, backslash \ and quotation mark " (ASCII: 32, 92, 34)) must also
    be preceded by a backslash \ (e.g. "\ \\\"").
    For more information, please refer to this similar thread.
    https://social.technet.microsoft.com/Forums/exchange/en-US/69f393aa-d555-4f8f-bb16-c636a129fc25/what-are-valid-and-invalid-email-address-characters
    Best Regards.

  • 4400 Controllers - Best Practise for connecting to wired network

    At one time the best practise recommendation for wireless was to treat the traffic as untrusted and separate it from the wired network by firewalls and intrusion detection. A lot of the reason for this was the weakness of WEP. Now with strong authentication and encryption (e.g., WPA2 and EAP-TLS) in use, and the use of wireless controllers, I'm wondering what the industry is recommending (and doing in case the actions aren't the same as the recommendations).
    Are organizations connecting the wireless controllers directly to the internal network or are they separating them with a firewall and IDS infrastructure? If the latter, what does the architecture look like? Are there documents on the Cisco site or on the Internet that show how the controllers could be firewalled? Everthing I've seen shows connections directly to the internal network. Is firewalling the controller an overreaction to the historical paranoia from the WEP days?

    The argument would be that regardless of what security you put on the wireless, you still don't have the physical security - i.e. someone doesn't need to walk into your building to use your network.
    Beyond that if you're using strong auth/enc you can currently be considered safe, we have customers using that direct into their LANs (but then, we also have customers with WEP direct into their LANs!)...
    If you are concerned or really need belt 'n' braces security, then go down the firewall/IDS route - there's no harm in it if you have the money. It really depends how much functionality and ease of use you need to balance against it.
    Aaron
    Please rate helpful posts

  • SAP BEST PRACTISE BI-Purchasing Volume Dashboard issue

    Hello,
    I am working on Purchasing Volume Dashboard (from SAP BEST PRACTISE BI package), I adapted Crystal Reports sources of this dashboard so that they connect to our local database and successfully generated the Export.xls, I Imported this Export.xls file into Purchasing Volume Dashboard.xls, added and configured Live Office Connections (ticking"Refresh before components are loaded" for each Live Connections.
    The issue is that when I click on PREVIEW the four components (Charts and Scorecard) don't refresh simultaneously.
    I have to click once on REFRESH button to have the first component refreshed with data then to click again to have the second component refreshed then click again and again !
    I don't understand why those components don't refresh in the same time !!
    Did one of you ever encountered this issue ?
    many thanks for your help,
    Regards
    Christiane

    Hi,
    Make sure your web service URL correct in Live Office connection and also in Xcelsius data manager.
    Did you check all connection in refresh button proprties? you may try selecting "Refresh after component are Loaded" in Refresh button properties Behavior tab.
    I think Xcelsius refresh are serial refresh so it may be possible that first component refresh is still in progress but you are expecting other component to refresh.
    Click on "Enable Load Cursor" in data manager's Usage tab, it will give you visibility of refresh. If anything refreshing you will see hour glass.
    Cheers

  • Basics:  Best practise when using a thesaurus?

    Hi all,
    I currently use a function which returns info for a search on our website, the function is used by the java code to return hits:
    CREATE OR REPLACE FUNCTION fn_product_search(v_search_string IN VARCHAR2)
    RETURN TYPES.ref_cursor
    AS
    wildcard_search_string VARCHAR2(100);
    search_results TYPES.ref_cursor;
    BEGIN
    OPEN search_results FOR
    SELECT
              DCS_PRODUCT.product_id,
              DCS_CATEGORY.category_id,
              hazardous,
              direct_delivery,
              standard_delivery,
              DCS_CATEGORY.short_name,
              priority
              FROM
              DCS_CATEGORY,
              DCS_PRODUCT,
              SCS_CAT_CHLDPRD
              WHERE
              NOT DCS_PRODUCT.display_on_web = 'HIDE'
              AND ( contains(DCS_PRODUCT.search_terms, v_search_string, 0) > 0)
              AND SCS_CAT_CHLDPRD.child_prd_id = DCS_PRODUCT.product_id
              AND DCS_CATEGORY.category_id = SCS_CAT_CHLDPRD.category_id
              ORDER BY SCORE(0) DESC,
              SCS_CAT_CHLDPRD.priority DESC,
              DCS_PRODUCT.display_name;
    RETURN search_results;
    END;
    I want to develop this function so that is will use a thesaurus in case of no data found.
    I have been trying to find any documentation that might discuss 'best practise' for this type of query.
    I am not sure if I should just include the SYN call in this code directly or whether the use of the thesaurus should be restricted so that it is only used in circumstances where the existing fuction does not return a hit against the search.
    I want to keep overheads and respose times to an absolute minimum.
    Does anyone know the best logic to use for this?

    Hi.
    You want so much ("... absolute minimum for responce time...") from OracleText on 9.2.x.x.
    First, text queries on 9.2 is so slowly than on 10.x . Second - this is bad idea - trying to call query expansion functions directly from application.
    My own expirience:
    The best practise with thesauri usage is:
    1. Write a good searcg string parser which add thes expansion function (like NT,BT,RT,SYN...) directly in result string passed through to DRG engine.
    2. Use effective text queries: do not use direct or indirect sorts (hint DOMAIN_INDEX_NO_SORT can help).
    3. Finally - write effective application code. Code you show is inefficient.
    Hope this helps.
    WBR Yuri

  • Request for howto - error processing best practise

    Hi JDev Team. Something I would like to see in a future HOWTO would be error handling in a BC4J/JSP application. What is best practise? How do we make sure that when a database error occurs, we can trap the error and provide a friendly error message, or failing that, at least ensure the standard error is usable by a maintenance programmer. For eg. the following error occurs if a referential constraint restricts the delete:
    javax.servlet.jsp.JspException: JBO-26041: Failed to post data to database during "Delete": SQL Statement " DELETE FROM TECHTRANSFER.TTSITES Sites WHERE SITEID=:1".
    in fact the same error message is displayed for almost any database error - the programmer can't fix the problem when he has no idea what it is!! (same with update and insert)
    I wasn't going to request this until I had read all of the help available on error processing but the way this project is going I won't get time. If you think that it is adequately covered in the help, then fine, just let me know where.
    Thanks,
    Simon

    You can enclose your bc4j/jsp code with a try / catch expression. That way if a failure occurs, you can trap it, display a friendy error, and do whatever you want with the exception.
    What I have been doing for develpment purposes, is send via email a modified errorpage.jsp. Here is what gets emailed to me (*'s in potentially sensitive data) and displayed to the screen (I'm eventually going to replace all the displayed garbage with something friendly):
    An error occured in application PDC User Administration
    User Session Properties:
    Sesion ID: *********
    App ID: *********
    User Name: *********
    User ID: *********
    Priv Role: *********
    Password: *********
    Org No: *********
    First Name: skunitzer
    Last Name: ANALYST
    App Title : PDC User Administration
    Current Url: insertNewUser.jsp
    Specific error is javax.servlet.jsp.JspException: JBO-25013: Too many objects match the primary key oracle.jbo.Key[1423 ].
    Parameters:
    LastName
    Kunitzer
    EmailAddress
    [email protected]
    FirstName
    SteveLiveTest
    OrgNo
    PhoneWorkNo
    I have no phone #
    ExpireDate
    2001-04-26
    ExpireDateString
    jRQiIsFGANIbrGlihGTl[epofZmSNgEkGqbHN@iErHNPRi
    UserID
    UserPrivs
    Exception:
    javax.servlet.jsp.JspException: JBO-25013: Too many objects match the primary key oracle.jbo.Key[1423 ].
    Message:
    JBO-25013: Too many objects match the primary key oracle.jbo.Key[1423 ].
    Localized Message:
    JBO-25013: Too many objects match the primary key oracle.jbo.Key[1423 ].
    Stack Trace:
    javax.servlet.jsp.JspException: JBO-25013: Too many objects match the primary key oracle.jbo.Key[1423 ].
    at java.lang.Throwable.fillInStackTrace(Native Method)
    at java.lang.Throwable.fillInStackTrace(Compiled Code)
    at java.lang.Throwable.<init>(Compiled Code)
    at java.lang.Exception.<init>(Compiled Code)
    ...Stack Trace goes on but I won't bother with it anymore...
    While not always as specific as I would like, I have not had too much trouble hunting down the errors.
    null

Maybe you are looking for

  • How to reset the TMP password?

    Hi, to all, this is my first post on this forum. I've got Lenovo ThinkPad Z61m, and got problem with the Client Security Solution. This is the message when I try to configure this program: " The Trusted Platform Module (TPM) on this system has been c

  • CS4 not working with snow leopard

    Has anyone had any issues with CS4 Extended after upgrading to SnowLeopard? After upgrading to Snow Leopard osx10.6.8, my CS4 will not open. It crashes about 30 sec after i try to open it. I have tried restarting, but with no luck. Does anyone have a

  • Does Premiere Elements 8 work with Organizer 10

    My operating system  is 64 bit Windows 7. My computer exceeds the system requirements for Premiere Elements 8 (PRE 8)and Photoshiop Elements 10 (PSE 10). Here is the background to my question. I offer this in case some may question why I don't upgrad

  • Editing Message and resending in XI Moni

    Hi all, how do we edit a message in moni and resent it?

  • OBIEE Web service Html View Service

    Please help us with the solution I am facing the problem of displaying the report to the page ; the page is empty and when view source the html is encoded