Casting for HashMap
Hi,
I have a class called ThreadInfo:
public class ThreadInfo{
public ChatWindow threadID;
public String ip;
public String username;
public boolean windowOpen;
public boolean linkEstablished;
ThreadInfo(){
windowOpen = false;
linkEstablished=false;
}I also have a class:
public class ServerStatus {
private HashMap threadList;
ServerStatus() {
threadList = new HashMap();
}now if I want to put a value in the HashMap, I would do:
public void insertNewThread(String key, ThreadInfo info) {
threadList.put(key,info);
}right?
and about retrieving a value, does this sound correct?
public ThreadInfo getThread(String key){
ThreadInfo requiredInfo = (ThreadInfo)threadList.get(key);
return requiredInfo;
}My query is really about this casting thing because in the API the get method returns an object, but since I know I am inserting a ThreadInfo class instance in the map, I thought that the casting here would give me the correct result.
any insight to this is highly appreciated
thanks,
Talal
Be careful doing this.
HashMap can contain null as a value. null cannot be
cast. Therefore you might want to test the value
returned by get(key) for null before trying to cast it
to your return type.
matfudI do not believe the above is correct.
Example:
import java.util.*;
public class Test68 {
public static void main(String[] args) {
HashMap hm = new HashMap();
hm.put("aaa", null);
String s = (String)hm.get("aaa");
System.out.println(s);
ArrayList al = (ArrayList)null; // And just for the fun of it
}C:\j2sdk1.4.0\Test>javac Test68.java
C:\j2sdk1.4.0\Test>java Test68
null
C:\j2sdk1.4.0\Test>
Similar Messages
-
Difference between narrow() method usage and simple class cast for EJB
Hi,
I have a very simple question:
what is the difference between PortableRemoteObject.narrow(fromObj,
toClass) method usage and simple class cast for EJB.
For example,
1)
EJBObject ejbObj;
// somewhere in the code the home.create() called for bean ...
ABean a = (ABean)PortableRemoteObject.narrow(ejbObj,ABean.class);
OR
2)
EJBObject bean;
// somewhere in the code the home.create() called for bean ...
ABean a = (ABean)ejbObj;
Which one is better?
P.S. I'm working with WL 6.1 sp2
Any help would be appreciated.
Thanks in advance,
Orly[email protected] (Orly) writes:
Hi,
I have a very simple question:
what is the difference between PortableRemoteObject.narrow(fromObj,
toClass) method usage and simple class cast for EJB.
For example,
1)
EJBObject ejbObj;
// somewhere in the code the home.create() called for bean ...
ABean a = (ABean)PortableRemoteObject.narrow(ejbObj,ABean.class);
OR
2)
EJBObject bean;
// somewhere in the code the home.create() called for bean ...
ABean a = (ABean)ejbObj;
Which one is better?(1) is mandated by the spec. It is required because CORBA systems may
not have sufficient type information available to do a simple case.
P.S. I'm working with WL 6.1 sp2 You should always use PRO.narrow()
andy -
Can sumone please tell me how to implement "Generics for Hashmap in java"
Please guide me in the required direction.http://www.google.co.za/search?hl=en&q=%2Bjava+%2Bgenerics+%2Bhashmap&meta=
-
Why people write Wrapper class for HashMap? Why not directly use the HashMap?
I thought that the term wrapper class is generally
used to signify one class having an instance of
another class inside it. And not one class
deriving from another.
But thats just me.I think that is just you. :)
I consider "wrapping" as having a subset of the functionality of another class. This could be containing or extending, in my opinion.
Consider:
// only partially functional vector for JButtons...
// class containing Vector
public class JButtonVector
Vector vec = new Vector();
public void add(JButton button)
vec.add(button);
public JButton get(int index)
if(index >= vec.size() || index < 0)
throw new IllegalArgumentException(...);
return (JButton)vec.get(index);
// class extending Vector
class JButtonVector2 extends Vector
public void add(JButton but)
super.add(but);
public JButton get(int index)
return (JButton)(super.get(index));
}Problem with the second class is that it also allows adding of regular Objects. That might not be desirable (in this case, it is definitely not). -
How is the performance for HashMap.get()
hi all
i just want to ask you guys how quick the hashmap.get() runs for a given key, if there are thousand of entries in the hashmap. thanksIf you want to know how something is going to perform, write a tiny program and test it. Either put it on a profiler, or just put time markers around a big loop. Here's something that somebody (UJ, I think) came up with recently for comparing casting vs. toString after extracting from a Map. It should be easy to adapt to just the Map.get() timing. In fact, I think I added a chunk to do just that, as a control. Knock yourself out. import java.util.*;
public class MapTiming {
Random rnd = new Random(13L);
public static void main(String[] args) {
int numEntries = Integer.parseInt(args[0]);
Integer key = Integer.valueOf(args[1]);
new MapTiming().zillion2(numEntries, key);
void zillion2(int numEntries, Integer key) {
HashMap map = new HashMap();
int ix;
for (ix = 0; ix < numEntries; ix++) {
int entry = rnd.nextInt();
map.put(new Integer(entry), String.valueOf(ix));
map.put(key, String.valueOf(ix));
final int LOOPS = 10000000;
final int TIMES = 5;
long time;
for (int j=0; j<TIMES; j++) {
time = System.currentTimeMillis();
for (int i=0;i<LOOPS; i++) {
String item = map.get(key).toString();
System.out.println("toString= " + (System.currentTimeMillis()-time));
for (int j=0; j<TIMES; j++) {
time = System.currentTimeMillis();
for (int i=0;i<LOOPS; i++) {
String item = (String)map.get(key);
System.out.println("cast= " + (System.currentTimeMillis()-time));
for (int j=0; j<TIMES; j++) {
time = System.currentTimeMillis();
for (int i=0;i<LOOPS; i++) {
Object obj = map.get(key);
System.out.println("get= " + (System.currentTimeMillis()-time));
for (int j=0; j<TIMES; j++) {
time = System.currentTimeMillis();
for (int i=0;i<LOOPS; i++) {
String item = map.get(key).toString();
System.out.println("toString= " + (System.currentTimeMillis()-time));
for (int j=0; j<TIMES; j++) {
time = System.currentTimeMillis();
for (int i=0;i<LOOPS; i++) {
String item = (String)map.get(key);
System.out.println("cast= " + (System.currentTimeMillis()-time));
for (int j=0; j<TIMES; j++) {
time = System.currentTimeMillis();
for (int i=0;i<LOOPS; i++) {
Object obj = map.get(key);
System.out.println("get= " + (System.currentTimeMillis()-time));
} -
Type casting for properties accessed in COM Object
I have a com object that I need to access which provides my a
list of addresses in an Array. The object give me a property that
has a count for the number of addresses and then I have a loop that
calls the property which contains the address details to get each
individual address each time passing to the property the INDEX
value on the loop.
This errors out each time.
The error I get is
Error casting an object of type to an incompatible type.
This usually indicates a programming error in Java, although it
could also mean you have tried to use a foreign object in a
different way than it was designed.
It appears the the variable type of the index is not
compatible with the property of the component(which is an int).
IS there some way to type cast the variable used as the index
for CFLOOP to that of an INT?You can try to use the JavaCast("int", myValue) function. It
works great for Java objects, but I'm not sure how well it will
work for COM. Worth a try, I guess.
In your case it would be something like:
<cfobject type="COM" context="INPROC" action="create"
name="MR" class="DLLNAME">
<cfloop from="1" to="#AddressCount#" index="i">
<cfset VDname = mr.vdsname(JavaCast("int", i))>
<cfset VDaddress = mr.vdsaddress(JavaCast("int", i))#>
<cfset VDXML = mr.VDSXML(JavaCast("int", i))>
</cfloop> -
Hi,
I have a class I created, call it MyClass. It looks like this:
public String myString;
public final String toString() {
return myString;
public boolean equals(MyClass mc) {
return (mc != null && myString.equalsIgnoreCase(mc.toString()));
}When I use objects of type MyClass as the keys to a HashMap when doing a put(), duplicate keys seem to be allowed. And when I query, knowing that I have an entry for a key, I get null. However, when I change my get() and put() to use MyClass.toString() as the key, everything works fine.
It seems to me that the JVM must be assuming that different instances of objects of type MyClass are different and thus a new key+value is created when "putting" instead of the old value being overwritten. But MyClass has an equals() method, so when putting, why doesn't it tell the JVM that the key already exists?
Thanks,
JeffTrue, I missed that.
Were you thinking that the HashMap is going to use the equals you provide that takes MyClass as an arg? It won't. It uses the one that takes Object, which means you'll be using Object's equals, which compares references, so no MyClass can ever be equal to another.
You need to override equals (with the Object argument) and override hashCode. -
Requirement for object key for HashMap
Hi,
I would like to put the object to HashMap keyed by my own object. what is the requirement for the class to be key? I have a method boolean equals(Object o) defined in the key class, My key is composed by 2 ids, so in the equals method I compared the 2 ids. but it seems can't get the value out. Please help. ThanksHow do I supposed to do the hashCode? If myKey1.equals(myKey2) returns true, then myKey1.hashCode() must return the same value as myKey2.hashCode(). One consequence of this is that if something is not used to compuate equals(), then it must not be used to compute hashCode(). (Note that the reverse is not true. That is, if two objects are not equal, they can still return the same value from hashCode(), and hence, if some data is used for equals() it may still be left out of hashCode().)
You want hashCode to be 1) quick & easy to compute and 2) "well distributed" or "mostly unique. If you know how hashcodes are used (in the general sense, not just the Java hashCode() method) then you should understand why those properties are desirable. If not, just ask.
The most common approach is to use some subset of the object's fields in computing the hashCode. If you have a Person object with lastName, firstName, birthdate, height, weight, address, phone number, you probably wouldn't use all those fields. You could just lastName, or maybe a combination of lastName and firstName.
One generally combines multiple pieces by taking XORing (the "^") operator the individual pieces (for primitives) or their hashcodes (for objects). For example, in the Person example: public int hashCode() {
return lastName.hashCode() ^ firstName.hashCode(); // but make sure to check for null first
} -
I've seen some codes have the type in parenthesis then the value... like:
(long) Math.random()*1000What's that do?The promotion from an int to a long, float, or double
(for example) can be done without a cast.
int i = 123;
double d = i; // all three of these are okay w/o cast ...
long el = i; // no precision will be lost ... "widening conversions"
float f = i;
The de-promotion (is that even a word?) of a double to a
float, long, or int can not be done without a cast. These
go "against the flow" of direction of Fred's sequence of types.
double d = 123.45D;
int i = (int) d; .. cast is required for these "narrowing conversions"
long el = (long) d;
float f = (float) d;
Why would you do this stuff ? As alluded to in an earlier post,
adding two integers is not guaranteed to result in an integer -
it could overflow. Assigning the result to a long will alleviate
the problem.
Or, say you have a long and you know its a "small" (ie, int sized)
long ... and you want to pass it to a method the requires an int
parameter ... a cast would accomplish this ...
boolean doSomethingRequiringAnInt( (int) aLongValue );
Hope this helps a little ...
Eric -
Records and Objects, Cast for PL/SQL Type RECORD and SQL Type OBJECT
Hi seniors:
In my job, we have Oracle 10g, programming with Packages, the parameters are PL/SQL Types,
Example:
PACKAGE BODY NP_CONTROL_EQUIPMENT_PKG
IS
TYPE TR_EQUIPMENT_OPERATION IS RECORD(
wn_npequipmentoperid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npequipmentoperid%TYPE,
wv_npactiveservicenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npactiveservicenumber%TYPE,
wv_npspecification ORDERS.NP_SPECIFICATION.npspecification%TYPE,
wv_nptype ORDERS.NP_SPECIFICATION.nptype%TYPE,
wn_nporderid CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.nporderid%TYPE,
wn_npguidenumber CONTROL_EQUIPMENT.NP_EQUIPMENT_OPERATIONS.npguidenumber%TYPE,
wd_npdevolutionprogramdate CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npdevolutionprogramdate%TYPE
TYPE TT_TR_EQUIPMENT_OPERATION_LST IS TABLE OF TR_EQUIPMENT_OPERATION INDEX BY BINARY_INTEGER;
PROCEDURE SP_GET_EQUIPMENT_OPERATION_LST(
an_npequipstatid IN CONTROL_EQUIPMENT.NP_EQUIPMENT_STATUS.npequipstatid%TYPE,
at_equipment_operation_list OUT TT_TR_EQUIPMENT_OPERATION_LST,
av_message OUT VARCHAR2
IS
BEGIN
SELECT EO.npequipmentoperid,
EO.npactiveservicenumber,
S.npspecification,
S.nptype,
EO.nporderid,
EO.npguidenumber,
ES.npdevolutionprogramdate
BULK COLLECT INTO at_equipment_operation_list
FROM NP_EQUIPMENT_OPERATIONS EO,
NP_EQUIPMENT_STATUS ES,
ORDERS.NP_ORDER O,
ORDERS.NP_SPECIFICATION S
WHERE EO.npequipstatid = ES.npequipstatid
AND EO.nporderid = O.nporderid
AND O.npspecificationid = S.npspecificationid
AND EO.npequipstatid = an_npequipstatid;
EXCEPTION
WHEN OTHERS THEN
av_message := 'NP_CONTROL_EQUIPMENT_PKG.SP_GET_EQUIPMENT_OPERATION_LST: '||SQLERRM;
END SP_GET_EQUIPMENT_OPERATION_LST;
END;
Procedures calls other procedures and passing parameters IN OUT defined that PL/SQL Types. The problem appears when the access is through Java. Java can't read PL/SQL Types because only read SQL Types (Types defined in SCHEMA):
CREATE OR REPLACE
TYPE TO_EQUIPMENT_OPERATION AS OBJECT (
wn_npequipmentoperid NUMBER,
wv_npactiveservicenumber VARCHAR2(15),
wv_npspecification VARCHAR2(8),
wv_nptype VARCHAR2(2),
wn_nporderid NUMBER,
wn_npguidenumber NUMBER,
wd_npdevolutionprogramdate DATE
CREATE OR REPLACE
TYPE TT_EQUIPMENT_OPERATION_LST
AS TABLE OF "CONTROL_EQUIPMENT"."TO_EQUIPMENT_OPERATION"
Java can read this SQL Types. The problem is how cast OBJECT to RECORD, because I can't execute that:
DECLARE
wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
BEGIN
SELECT EO.npequipmentoperid,
EO.npactiveservicenumber,
S.npspecification,
S.nptype,
EO.nporderid,
EO.npguidenumber,
ES.npdevolutionprogramdate
BULK COLLECT INTO wt_operation_lst
FROM NP_EQUIPMENT_OPERATIONS EO,
NP_EQUIPMENT_STATUS ES,
ORDERS.NP_ORDER O,
ORDERS.NP_SPECIFICATION S
WHERE EO.npequipstatid = ES.npequipstatid
AND EO.nporderid = O.nporderid
AND O.npspecificationid = S.npspecificationid
AND EO.npequipstatid = an_npequipstatid;
END;
and throws NOT ENOUGH VALUES, and I modified to:
DECLARE
wt_operation_lst TT_EQUIPMENT_OPERATION_LST;
BEGIN
SELECT TO_EQUIPMENT_OPERATION(EO.npequipmentoperid,
EO.npactiveservicenumber,
S.npspecification,
S.nptype,
EO.nporderid,
EO.npguidenumber,
ES.npdevolutionprogramdate)
BULK COLLECT INTO wt_operation_lst
FROM NP_EQUIPMENT_OPERATIONS EO,
NP_EQUIPMENT_STATUS ES,
ORDERS.NP_ORDER O,
ORDERS.NP_SPECIFICATION S
WHERE EO.npequipstatid = ES.npequipstatid
AND EO.nporderid = O.nporderid
AND O.npspecificationid = S.npspecificationid
AND EO.npequipstatid = an_npequipstatid;
END;
Worst is that I can't modify this procedure and PL/SQL Types will survive.
I have create a copy that CAST RECORD to OBJECT and OBJECT to RECORD too.
PROCEDURE SP_COPY_PLSQL_TO_SQL(
an_npequipstatid IN NUMBER,
at_dominio_lst OUT ORDERS.TT_EQUIPMENT_OPERATION_LST, --SQL Type
av_message OUT VARCHAR2
IS
wt_dominio_lst CONTROL_EQUIPMENT.NP_CONTROL_EQUIPMENT_PKG.TT_TR_EQUIPMENT_OPERATION_LST; --PL/SQL Type
BEGIN
SP_GET_EQUIPMENT_OPERATION_LST(an_npequipstatid, wt_dominio_lst, av_message);
IF av_message IS NULL THEN
at_dominio_lst := ORDERS.TT_EQUIPMENT_OPERATION_LST(ORDERS.TO_EQUIPMENT_OPERATION('','','','','','',''));
at_dominio_lst.EXTEND(wt_dominio_lst.COUNT - 1);
FOR i IN 1..wt_dominio_lst.COUNT LOOP
at_dominio_lst(i) := ORDERS.TO_EQUIPMENT_OPERATION(wt_dominio_lst(i).wn_npequipmentoperid,
wt_dominio_lst(i).wv_npactiveservicenumber,
wt_dominio_lst(i).wv_npspecification,
wt_dominio_lst(i).wv_nptype,
wt_dominio_lst(i).wn_nporderid,
wt_dominio_lst(i).wn_npguidenumber,
wt_dominio_lst(i).wd_npdevolutionprogramdate
END LOOP;
END IF;
END;
I would like that the CAST is direct. Somebody can help me?. Thank you so much!I am facing the same problem as u had...may I know how u solved ur probkem...
thanks,
kishore -
hi all:
Let me see if I can convey this thought clearly..
I am having logic problems... not coding issues...
My problem...
I have a class called JobBuilder and another class called RegistrationFile. The idea is that RegistrationFile has a mehod to write a Registration File called writeRegistrationFile(HashMap regFileParams). Note that the registration file is constructed based on values in the RegistrationFile... However the registration file construction and hence required information is different depending upon the file type... Thus I have created another method called getRegFileParameters(String filetype) in class RegistrationFile which can be called before the write method which will construct a HashMap with the required parameters neccessary for the specified type and return it to the calling class (JobBuilder). The information in the returned HashMap will contain the required and optional fields needed to create a the specific registration file... My idea is that registration file class returns this HashMap to the calling class JobBuilder and it will use the information in the HashMap to construct the appropriatte HashMap which can be passed back to the RegistrationFile method writeRegistrationFile(HashMap params) method in order to construct the registration file...
so for example say the calling class JobBuilder says ok I want to create a registration file that is of type 2d Drawing... so it will make the following call:
RegistrationFile rf = new RegistrationFile();
HashMap hm1 = rf.getRegFileParams("2d Drawing");
the above will execute and a hashmap of optional and required values will be returned to JobBuilder and will look something like this...
"GT_ATTRIB", "AFM_W,KEY;AFM_X,KEY;AFM_D,X;"
"NTK", "X,X;"
"FILE", "X,X,X;"
etc...
couple things to note...
X = optional
KEY = REQUIRED
also there may be X number of required records for GT_ATTRIB, or NTK, etc... multi valued input is seperated by commas and varying value/parameter pairs by semicolons...
Thus for GT_ATTRIB there may be some number of required fields like AFM_X, AFM_D, etc and each pair is seperated by a semicolon...
thus AFM_X, AFM_D eventually will translate to seperate records
i.e. in the registration file it might look like
GT_ATTRIB|AFM_X|11
GT_ATTRIB|AFM_D|Q.1
NTK|3|6
NTK|4|5
FILE|/var/tmp|file1.txt|<optional comment>
FILE|/var/tmp|file2.txt
etc... all of this would have be turned into a HashMap that is constructed and returned to the RegistrationFile.writeRegistrationFile (HashMap hm) that was constructed like the following...
HashMap hm2 = new HashMap();
hm2.put("GT_ATTRIB", "AFM_X,11;AFM_D,Q.1;");
hm2.put("NTK", "3,6;4,5;");
hm2.put("FILE", "/var/tmp,file1.txt,<optional comment>;/var/tmp,file2.txt;");
etc...
rf.writeRegistrationFile(hm2); // send it to registrationFile class and use the write method...
The logic problem i am having is that the they should be able to construct the previous by reading the HashMap that was returned earlier... specifying required and optional parameters... does anyone see how in the class JObBuilder I might accomplish this... somehow I need to read each "KEY", "VALUE" pair from the returned HashMap and then further break it down to distinguish the required attributes from the optional ones...
it seems that they will have to get the KEY (i.e. "GT_ATTRIB", "NTK", etc... and tear apart the "VALUE" (multi valued key) and determine what is required vs. optional and then to reconstruct it so that I can read it in RegistrationFile class.... i.e.
They may tear it apart as
"GT_ATTRIB", "AFM_X", "11";
"GT_ATTRIB", "AFM_D", "Q.1";
"NTK", "3", "6";
etc...
but in the end needs to be reconstructed like...
HashMap hm2 = new HashMap();
hm2.put("GT_ATTRIB", "AFM_X,11;AFM_D,Q.1;");
hm2.put("NTK", "3,6;4,5;");
hm2.put("FILE", "/var/tmp,file1.txt,<optional comment>;/var/tmp,file2.txt;");
etc...
rf.writeRegistrationFile(hm2); // send it to registrationFile class and use the write method...
does any of this make sense?
I need a way to tell what is required and optional based on the returned hashmap so that I can construct the correct hashmap which will be used in generation of the registration file...
I really do hope that makes sense and truly appreciate any time and help anyone can provide... pseudocode would be great.. to convey the idea if anyone has the time or desire...
thanks again..
echardrdYeah, you want to learn XML for ways to do this.
-
Kodo doesn't create table for HashMap?
Hi,
here is the metadata
<class name="ClassA" identity-type="datastore" >
<field name="hashMapField">
<map key-type="ClassB" value-type="ClassC"/>
</field>
</class>
I found that Kodo use a BLOB to represent the HashMap field instead of
using a new table. So we can't check the actually data in the db?
Thank very muchKodo 2.x can't persist maps where the key type is a first class object.
This feature will be in 3.0. -
HashMap<Object, Object> parameters = (HashMap<Object, Object>) request.getParameterMap();
this.setRequestContextMap(new HashMap(parameters));
This is giving me
warning: [unchecked] cast.
warning: [unchecked] unchecked call to HashMap(java.util.Map<? extends K,? extends V>) as a member of the raw type java.util.HashMap
How do I get rid of this warning?
- Jspecify type arguments for HashMap allocation:
e.g. new HashMap<Object,Object>(parameters) -
How to cast a BLOB to OrdImage
Hi,
How can I cast or convert a BLOB to OrdImage? For example,
<import...>
public class ConvertBlobToOrdImage {
public static void main(String args[]) throws Exception {
// Load the Oracle JDBC driver:
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database:
Connection conn =
DriverManager.getConnection(<"Your database connection">);
conn.setAutoCommit(false);
// Create a Statement:
Statement stmt = conn.createStatement();
String query = "SELECT blob FROM image_t where image_id = 1";
OracleResultSet rset = (OracleResultSet) stmt.executeQuery(query);
rset.next();
OrdImage imageProxy = (OrdImage) rset.getCustomDatum(1, OrdImage.getFactory()); // <-- java.lang.ClassCastException: oracle.sql.BLOB
rset.close();
int height = imageProxy.getHeight();
int width = imageProxy.getWidth();
System.out.println("Image Dimension: " + height + " x " + width);
System.out.println("Image Mime Type: " + imageProxy.getMimeType());
TIA,
Henryxwindy wrote:
Does anyone knows how to cast a HashMap to HashMap<String, Object>?
the session.getAttribute return only a HashMapthere is no way to do this safely
you can use this annotation to suppress unchecked warnings
@SuppressWarnings("unchecked") -
Error while reading UcdContext [trying to read / set application values for users]
Hi,
I am trying to write a program to store user selected values on NW7.3 Portal using "User Content Directory". I can see and read some code snippets on how to set and read the context but I am getting one error after another.
The error message I am getting is
"com.sapportals.portal.pcd.gl.PcdGlContext:service:[email protected]entClassLoader@84507ed@alive incompatible with interface com.sapportals.portal.pcd.gl.IPcdContext:sap.com/[email protected]der@f46d103@alive ". Code snippet is as given below at the end of the message.
1) I tried different ways to have a lookup and always gave message as "look up not found" and for pcd:portal_content came up with above error.
2) Once I read the UCD context, I would like to store some values based on user selection and store them. User may change the values whenever they like and I will be using the values for other purposes in another application.
3) Has any one successful in setting and reading UCD Context in NW 7.3. Will it be possible to share such sample code as the code snippets at http://help.sap.com/saphelp_nw73ehp1/helpdata/en/4a/8e1bce28e24dd8abd9f4de05e5587d/content.htm are not much of use unless I am able to read the UCD.
Thanks for your help!
Regards,
Raju
TestingUCD is my test application and the following is code snippet
InitialContext initialContext = null;
IPcdContext pcdCtx;
Hashtable env = new Hashtable();
env.put(UCD_INITIAL_CONTEXT_FACTORY, UCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, request.getUser());
env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);
try{
initialContext = new InitialContext(env);
//response.write("Before pcdCtx lookup");
try {
pcdCtx = (com.sapportals.portal.pcd.gl.PcdGlContext) initialContext.lookup("pcd:portal_content");
} catch(Exception e){
response.write("Some problem with lookup" + e.getMessage());Hi,
There are quite few differences in the standard code snippet given by SAP Help on UCD and the once that you put above in the question.
Below is standard snippet.
Hashtable<Object, Object> env = new Hashtable<Object, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
IPcdContext.UCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, user);
InitialContext ctx = new InitialContext(env);
pcdCtx = (IPcdContext) ctx.lookup("");
============================
Check the ones highlighted in BOLD and compare them in your code. In your code when ur doing initial lookup you are not using the Correct class type cast for the returned lookup object!
Your code shows as below:
pcdCtx = (com.sapportals.portal.pcd.gl.PcdGlContext) initialContext.lookup("pcd:portal_content");
But may be it shd have been something like below:
pcdCtx = (IPcdContext) initialContext.lookup("pcd:portal_content");
Pls verify and hopefully this resolves your issues around look up.
Thanks,
Swapna Priya.
Maybe you are looking for
-
Impact of use XMLEncoder to log transactions that use serialization
Hi, i have an application that uses serialization to communicate between client and server, i want to log this transactions in a xml file using XMLEncoder, using the method: public static void log(Object transaction) throws Exception { XMLEnc
-
Help withpoor-man's database replication
Hi All, We have a very small data model of six (6) tables and about 1500 records a day. Oracle 8i on SunOS. As part of a failsafe system we would like to develop a "poor man" database replication system. What we would like is, a hot swappable back up
-
How to get ITEM STOCK....??
Hi All, In the Alternative Items form(i,e in Inventory>Item Management>Alternative Items),in the matrix at present there are 3 columns ITEM NO REMARKS MATCH FACTOR I0001 34(stock on hand) I0002
-
Hp wireless scanner loosing connection
Problem: HP Officejet 4500 G510n-z Model number: CN547A Firmware version: MWM2FN1040AR Wifi Router: Linksys WRT54GL Wifi Version: 4.30.14 build 5, Oct. 26, 2009 This is a wireless printer. Generally it works, but I seem to have to 'wake it up' manua
-
Delete Address Book Duplicates with less info?
I was wondering how you would go about deleting duplicate contacts in Address Book 4.0.3? I want to keep the contacts I have which contain at least the "Company" field filled in (contacts with more info) but then delete the ones with less. If a bunch