1 step further
This is reference to an earlier post :-
http://forum.java.sun.com/thread.jsp?forum=54&thread=344129&tstart=0&trange=15
The idea behind the program as a whole is to create a client sever type of program that allows the client to send messages to a server and then retrieve a reply from the server. I have got that sussed out. But i want to make the program so it can connect to a server at different addresses. At the moment in the code it can only search for the server at the loop back address, or local server.
cpSocket = new Socket("localhost", 9111);
what i want to do is make the "localhost" a variable so when the program starts it will ask the user for a ip address, and then fill in the value of the variable instead of the "localhost".
I thought that this would work but it doesn't compile
public static void main(String[] args) throws IOException {
Socket cpSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try{
BufferedReader ha = new BufferedReader(
new InputStreamReader(System.in));
String input = ha.readLine();
System.out.println(" Host Address :" + ha);
}catch(IOException e){
System.out.println(e);
try {
cpSocket = new Socket(ha, 9111);
out = new PrintWriter(cpSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(cpSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to: localhost.");
System.exit(1);
It gives an error related to the ha variable in the cpSocket line of code.
Can you help?
Thankyou
>
public static void main(String[] args) throws
ows IOException {
Socket cpSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try{
BufferedReader ha = new BufferedReader(
new InputStreamReader(System.in));
String input = ha.readLine();--> that's the variable containing some value like "localhost"
System.out.println(" Host Address :" + ha);--> so here you should write the following:
System.out.println(" Host Address :" + input);
>
}catch(IOException e){
System.out.println(e);
try {
cpSocket = new Socket(ha, 9111);--> same here, try:
cpSocket = new Socket(input, 9111);
But i think, you will get a compiler error like "Variable "input" may not have been initialized" That is because you have declared and used the variable in two different try blocks. So just use one big try block.
public static void main(String[] args)
throws IOException
Socket cpSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try
BufferedReader ha = new BufferedReader(
new InputStreamReader(System.in));
String input = ha.readLine();
System.out.println(" Host Address :" + input);
cpSocket = new Socket(input, 9111);
out = new PrintWriter(cpSocket.getOutputStream(), , true);
in = new BufferedReader(new dReader
(new InputStreamReader(cpSocket.getInputStream()));
catch (UnknownHostException e)
System.err.println("Don't know about host: " + input);
System.exit(1);
catch (IOException e)
System.err.println("Couldn't get I/O for the connection to:" + input);
System.exit(1);
}
Similar Messages
-
Okay, so now I got a step further.
But I'm having a bit of another problem now, on my little project.
I tried Google the problem, but I couldn't solve it myself.
(For newcomers: I'm trying to make my WebView load a URL when my app starts up
My code for "main.m" is as following:
+#import <Cocoa/Cocoa.h>+
+#import <WebKit/WebKit.h>+
+@class WebView;+
+@interface Lectio : NSObject {+
++ IBOutlet NSWindow *window;++
++ IBOutlet WebView *webView;++
+@property (nonatomic, assign) NSWindow *window;+
+@property (nonatomic, assign) WebView *webView;+
@end
+@implementation Lectio+
+@synthesize window;+
+@synthesize webView;+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {+
++ NSString *urlText = @"http://www.apple.com"; // <-- ';' added; 2nd string instance removed++
++ [webView mainFrame loadRequest:[NSURLRequest requestWithURL:NSURL URLWithString:urlText]]; ++
@end
But now I'm getting this error:
+"_main", referenced from:+
+start in crt1.10.5.o+
+symbol(s) not found+
+collect2: Id returned 1 exit status+Ahh, no - sorry - didn't see them. I guess they sneaked in when I tried to make the text italic
My bad. -
Ok... im one step further on this whole "itunes wont open issue"
i seem to be having the smae trouble as many people in this forum. I found out that when you right click the icon, press run as, and try to run itunes, this window comes up for less then a second... luckly i got it with the screen shot button after a long time trying..
http://img356.imageshack.us/img356/1336/itunes29hv.jpggood lord ... you are the first person to ever report seeing that with the flash.
it's possible that you might have two different problems, here. let's try to see first if we can deal to that error message:
http://docs.info.apple.com/article.html?artnum=302398
keep us posted.
love, b -
Cube compression: Can you help me take example a step further?
Hi,
I read the following example on this site and it was very helpful but can you tell me what the result will be if I extend the example as shown below:
The original example in compressing a cube was:
.. This will reduce the number of records in the cube.
requestid date 0material 0amount
12345 20061201 3333 125
12346 20061201 3333 -125
12346 20061201 3333 200
will result to
requestid date 0material 0amount
20061201 3333 200
In this case 2 records are saved.
<b>What will be the result if it was:</b>
requestid-- date material--
0amount
12345 -
20061201 -
3333 -
125
12346 -
20061201 -
3333 -
-125
12346 -
20061201 -
3333 -
200
<b>12347 -
20061001 -
3333 -
10
12348 -
20061002 -
3333 -
5
12349 -
20060901----
2222 -
400
123410 -
20060901 -
1111 -
-300</b>Then it will be :
20061001 : 3333: 10
20061002 3333 5
20060901 2222 400
20060901 1111 -300
Ravi Thothadri -
HP LaserJet 4050N set up using IP *SUCCESSFUL step-by-step guide*
I have had sooo many difficulties in attempting to set up my HP LaserJet 4050N using an IP address connected to my iMac via Ethernet… but tonight I have finally succeeded! So for the benefit of anyone else who is having difficulties here is a complete step-by-step guide to how I achieved it.
1.
In ‘System Preferences’ in ‘Network’, I made sure that ‘Ethernet’ is set to the following:
‘Configure IPv4: Using DHCP’
Two numbers are given:
‘IP Address’ and ‘Subnet Mask’
(you might need to click ‘Renew DHCP Lease’ by clicking ‘Advanced’ and under ‘TCP/IP’ clicking ‘Renew DHCP Lease’)
WRITE BOTH OF THESE DOWN!
2.
Go to ‘Applications’ folder and click on ‘Utilities’ and open ‘Network Utility’. Click on the ‘Info’ tab and from the drop-down menu select ‘Ethernet’.
The ‘IP Address’ should be the same as that given in the ‘Network’ settings panel for the Ethernet port.
3.
On my HP LaserJet 4050N I went through the following menus:
Click the green ‘GO’ button until the display reads ‘Offline’
Click ‘MENU’ 7 times or until ‘EIO 2 JETDIRECT MENU’ shows
Press ‘ITEM’ button until ‘CFG NETWORKJ=NO *’ is displayed
Press ‘VALUE’ button until value reads ‘YES’
Press ‘SELECT’
Press ‘ITEM’ button until ‘CFG TCP/IP=NO*’ is displayed
Press ‘VALUE’ button until value reads ‘YES’
Press ‘SELECT’
Press ‘ITEM’ button until ‘BOOTP=NO’ is displayed (or press ‘VALUE’ button until value reads ‘NO’ and then press ‘SELECT’)
Press ‘ITEM’ button until
‘IP BYTE 1=XXX’ is displayed and where I have put ‘XXX’ using the ‘VALUE’ button enter the first number of the ‘IP’ address given in ‘Network Utility’.
Repeat this procedure for ‘BYTE 2, 3 AND 4’ by using entering a value each time using the ‘VALUE’ button and then pressing ‘SELECT’ before finally moving onto the next ‘IP BYTE’ value using the ‘ITEM’ button.
After all of the ‘IP’ values have been entered pressing the ‘ITEM’ button will display ‘SM BYTE 1=XXX’ – this is the ‘Subnet Mask’ value. Follow the same process as for the ‘IP’ address and enter the values given in the ‘Ethernet’ pane in ‘Network’ under ‘System Preferences’.
After entering the final ‘Subnet Mask (SM)’ value (BYTE 4) press ‘SELECT’ and finally press the green ‘GO’ button.
As soon as the green ‘GO’ button has been pressed the ‘IP’ value in both ‘Network’ (under ‘System Preferences’) and ‘Network Utility’ (Applications/Utilities) will change to display a new ‘IP’ address. The ‘Subnet Mask’ value displayed in ‘Network’ (under ‘System Preference’s should display the same ‘Subnet Mask’ value).
4.
Now close ‘Network Utility’.
Click on the ‘SHOW ALL’ tab in the open ‘NETWORK’ window.
Click on ‘Print & Fax’ in ‘System Preferences’.
Click on the ‘+’ tab on the left of the ‘Printers’ Pane.
Click on the ‘IP’ tab.
From the drop down menu ‘Select HP Jetdirect – Socket.’
Now in the Address field enter the ‘IP’ values that you entered in the printer (and that you wrote down earlier).
Once entered click ‘Add’.
I really hope that what has worked for me works for anyone else who is struggling to set up their HP printer using IP over Ethernet. Please post any success.
Kind regards
Neil.Thank you, Neil! Your instructions worked.
Several comments to clarify your instructions.
They mostly expose my simple minded understanding of computers....
1. At the line in part 3 beginning with " ‘IP BYTE 1=XXX’ is displayed...", the 'XXX' means the first set of numbers before the first '.' in the IP address. For an IP address of '78.123.4.56', that means '78'. You push the 'VALUE' button many times if the number is three digits. IP Byte 2 for the same IP address is '123'. Etc.
2. When you have finished all the steps, it works! What a relief.
The printer will appear in the print dialog box as an IP address.
3.You can change the name of the printer if you want.
Go to System Preferences>Print&Fax
Select the printer. (it is listed by its IP address number)
On the right side of the box will appear several buttons.
One button is 'Options & Supplies'. Click it.
Another box will drop down.
Choose 'General' from the 'General / Driver / Supply Levels' buttons at the top of the box.
The name of the printer will be defaulted as the IP address.
Type in whatever name you want for the printer
Click 'OK'
4. It may be possible to go one step further and connect the HP LaserJet 4050N
printer to the computer through an airport express, but I have
had enough frustration the past two weeks that I am not that curious. Yet.
Once again, thank you Neil!
Bob -
IDOC send step not running with exception in BPM?
Hello,
hope this is a simple question, but we are running with a problem here which is not answered well in SAP help or sdn. Possibly I didn´t find the right blog.
Situation:
We created a BPM with a send step (IDOC receiver) in a block (after a receive step starting the BPM) (That´s simple so far!).
The send step (async IDOC) in the block is connected in its attributes in field "system error" to an exception branch defined in the same block.
In this except.branch the process should send back to sender system a message via RFC and the last step in this exception branch is to interrupt the proces.
But now we tried to do a test. In this test we modified the receiver address of the send step (IDOC reciver) so that the receiver could not be reached, which results in a system error in SXMB_MONI (Service unavailable).
But this doesn´t work. The BPM starts the send step to the unavailable receiver, SXMB_MONI shows a system error step, but then the BPM continues with the next step after the block without starting the exception branch.
Any idea why the exception branch is not called?
Best regards
DirkHello again,
we are one step further now.
We did the same with an RFC instead of the IDOC send step.
Same result:
The service is not reachable. So the step results in an system error.
But as we could see in the monitoring SXMB_MONI the block with the exception and this send step (RFC) is passed before the step gives back this error!
So it looks like connection problems do not trigger an exception?
Any help is welcome!
Best regards
Dirk -
Basic Panel further improvements
I've played around with the new Development Basic Panel. Not easy at the beginning but quite consistent. I like the way the histogram is divided in sections and that these sections are logically organised in tools. I wonder if it's possible to go one step further :
by having a TAT for these tools : we have it for the tone curve, why not for the Basic: for exposure, highlights, shadows, black and white? It could be time saving and maybe more intuitive to interact directly onto the picture;
by having a clipping overlay for all the sections, not only for the black and the white at the beginning and the end of the histogram; this way we could see wich part of the picture will be affected by each tool.
Sounds good (and possible) or what?HEAD Productions wrote:
I don't care for them to be arranged in the "workflow order" as Victoria Bampton has suggested. Each photo requires a different approach and an order that relates to the histogram would be of more help.
Well, you may as well adapt and adopt the current order because, believe me, they won't be changed from the order they are in with the current beta. The reason the order is what it is is because the engineers wanted the order to indicate the suggested order in which the controls are designed to be used. Even in early testing, the testers tried to fight the current order up to the point where over time, it was obvious that the current order was optimal for most images in PV 2012.
What you really need to do is forget how you adjusted images in the previous process versions and adapt your edits to the new PV 2012. While some of the controls may share a slight similarity with the previous controls, they are different enough that trying to use old logic for the new controls will only frustrate you.
Think of them as Exposure and Contrast being the main tools, Highlights and Shadows as fine tuning the previous adjustments by recovering highlights and opening up shadows and Whites and Blacks as the final tune to adjust the end points, if needed (often they aren't). -
BSOD experience with CLEAN INSTALL on new hard drive...next step?
Much has been written about the BSOD experiences of those upgrading to Leopard and the conflict with third party software enhancements already on their Tiger system. And apparently those fixes are working for some. I may be in the minority, but I own a Mac Pro and have a boot drive for Tiger and a second boot drive, brand new and zeroed out, on which I installed Leopard.
When I go to start Leopard, I get either the BSOD or it will go one step further, bring me to the Leopard desktop, then hang...with a movable mouse but no functionality. In my case, since I am doing a fresh install with no Tiger software on the new hard drive, what could be causing the conflict? Has anyone else out there experienced my specific problem? And have their been any suggestions posted on a fix for this situation.
Obviously the CLEAN INSTALL experience of Leopard is not immune from the installation BSOD problems of the TIGER UPGRADERS.
I would love to hear from others experiencing these BSOD issues with their CLEAN INSTALLS and any possible workarounds.
Many thanks,
JohnI think the issue is installing 10.5 on a different drive than the boot drive. I would recommend swapping the drives, making the 10.5 the physical boot drive and Tiger the secondary.
I have done two clean installs on two different machines with no issue. A 3rd machine was upgraded with no issues as well.
Asking other users for sob stories helps no one. Asking for resolution however, is key. -
An Elephant stepped on my Thinkpad - Rescue and Recovery
My backup solution for my thinkpad is an external usb drive using Rescue and Recovery which I keep at my place of work. So if I lose my laptop or it gets stolen or an elephant steps on it (at the zoo?), I still have my backup.
And if the building burns down where the usb drive is stored, I still have my laptop which I always take home every night. I think its a pretty good redundancy solution. The only risk is if I go out for lunch, leaving the thinkpad in the office and the building burns down destroying the laptop and external hard drive together. Its a risk I'm willing to accept.
Now most backup systems have a "recovery disk" where if your computer stops working or is subject to one of the disasters mentioned above, you can load this disk into another computer, boot into a recovery operating environment and recover your precious files. Thinkpad's Rescue and Recovery system goes one step further where you can have the recovery environment on the usb hard drive itself. All you have to do is plug it in and turn on your computer to boot into the recovery operating system. Great idea!
Well I thought......and here is my dilemma....
If my thinkpad is stepped on by an elephant, I would naturally plug my usb drive into my desktop to recover my data files. The problem is, my desktop isn't a Lenovo...so the Rescue and Recovery operating environment doesn't load into memory. It seems to go into this continuous loop of trying to load but fails. Remember I don't want to install Rescue and Recovery onto my desktop, I just want it to load into memory so that I can get access to my back up and transfer my data files to my desktop until such time when I purchase another Thinkpad.
So my question to this forum is; is it true? is Rescue and Recovery crippled in this way that it only works on Lenovo branded machines, even if your Lenovo has been stepped on by an elephant and you don't have another Lenovo immediately on hand?
I mean, is the Rescue and Recovery back up solution, just an external hard drive or is it really a external hard drive and another Lenovo computer
Or is there something (I hope) I have to do in the desktop Bios to be able to get Rescue and Recovery working?
Just wondering...has anyone done a similar test?Hello,
Hopefully this email reaches you before an elephant steps on your ThinkPad.
You might find a white paper I wrote about a year ago of interest: It's called Options for backing up your computer [PDF, 861KB] and goes over some of the various ways in which home and SOHO users can backup their systems. It's product and operating system agnostic, so it doesn't get into specific recommendations for tools to use, but does go over the types of backup hardware and software available. One thing it does not cover is cloud-based solutions, though, so that's something you'll want to look into separately.
You didn not mention which model of ThinkPad you had, but you might want to look into something like a Pelican Case for yours, if it fits. While I'm not sure it would be very effective against elephants, it should give you a chance against probably anything smaller than one of the big cats.
Regards,
Aryeh Goretsky
I am a volunteer and neither a Lenovo nor a Microsoft employee. • Dexter is a good dog • Dexter je dobrý pes
S230u (3347-4HU) • X220 (4286-CTO) • W510 (4318-CTO) • W530 (2441-4R3) • X100e (3508-CTO) • X120e (0596-CTO) • T61p (6459-CTO) • T43p (2678-H7U) • T42 (2378-R4U) • T23 (2648-LU7)
Deutsche Community Comunidad en Español Русскоязычное Сообщество -
MDM Workflow:branch step.
Hi ,
Can anyone explain the use of Branch step?
Hw can u connect it can anyone elaborate?
Satisfactory answers will be rewarded points
Regards
NishaHi,
i give u a short Example through workflow, using this you will come to know how to use Branch Step.
>Assign---->Stop1
Start--->Branch
>Stop2
Suppose in your Main table there is a field which you want should always have some value say this field is Product ID
So, in Main table select Validations Pane and Create a validation say validation Name Mandatory Product ID
Here validation shud contain expression as IS_NOT_NULL(Product ID)
Create a new field of type Text Say Status in Main table.
Create an assignment say Approved Records in Assignment Pane Select Property Table Field = Status in assignment expression write say Approved
During configuring workflow in Branch Step select Property Validations = Mandatory Product ID
on selecting this two more Properties get Enabled Select Property Mandatory Product ID = Assign and Property Default = Stop2 , All the steps should be connected properly using Connector,
For Assign Step select Property Assignment = Approved Records and this Assign step further connect to Stop1
So using this workflow it will fill the values Approved in the field Status for all the records having Product ID and for failed records it go directly to stop2
Hope it will Help you,
Rewards if Useful.....
Mandeep Saini
Edited by: Mandeep Saini on Jun 19, 2008 7:28 AM -
How can i slide a sound track one frame at a time in Pre 10
i do a lot of music videos where i record audio separtly from the video and then sync them and i have a lot of trouble getting them in sync, does anyone have any good tricks to do this? also, can i move said sound track one frame at a time in either direction to help get these tracks to sync up?
ThanksIf you zoom to the max, and watch that little TimeCode box (it pops up, when you begin dragging), just look at the last two digits, as those are the Frames. Even with my clumsy hands and fingers, I can nail the displacement to Frame-accurate standards.
Now, some other NLE's go a step further, in that when the Clip is Selected, one can nudge it along, with modifier keys and the Left-Right Cursor keys. I do not think that has been added to PrE 10, but would be a great Feature Request.
Good luck,
Hunt
[Edit] Well shut my mouth! After you Select the Clip (unlinking with Alt+click, if muxed), just hold down the Alt key, while hitting the Left-Rigt Cursor keys!!!! Forget that Feature Request.
Message was edited by: Bill Hunt -
Hello everybody. I recently bought a new Mac Pro (2x Quad-Core Intel Xeon, 2,4GHz, running OS X 10.6.8) and just encountered a very strange error at bootup. 1 out of 10 system boots take up much longer and end up in having the desktop with a light blue layer on the screen, being able to move the mouse cursor but not click on any item. I'm using the magic mouse + trackpad + wireless keyboard but have also tried to use a cable mouse with no success. The only way to shutdown the system is to force a power down. Then the computer will boot up fine again several times. Then again, the same error occurs. This is what the kernel log says. Have a look at the bold line: this is where the system hangs much longer at startup (I'm using verbose mode at startup).
Thank you in advance for your help!
Dominik
16.07.11 11:51:35 kernel Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64
16.07.11 11:51:35 kernel vm_page_bootstrap: 3559132 free pages and 94500 wired pages
16.07.11 11:51:35 kernel kext submap [0xffffff7f80800000 - 0xffffff8000000000], kernel text [0xffffff8000200000 - 0xffffff8000800000]
16.07.11 11:51:35 kernel standard timeslicing quantum is 10000 us
16.07.11 11:51:35 kernel mig_table_max_displ = 73
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=0 LocalApicId=0 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=1 LocalApicId=32 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=2 LocalApicId=2 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=3 LocalApicId=34 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=4 LocalApicId=18 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=5 LocalApicId=50 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=6 LocalApicId=20 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=7 LocalApicId=52 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=8 LocalApicId=1 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=9 LocalApicId=33 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=10 LocalApicId=3 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=11 LocalApicId=35 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=12 LocalApicId=19 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=13 LocalApicId=51 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=14 LocalApicId=21 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=15 LocalApicId=53 Enabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=16 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=17 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=18 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=19 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=20 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=21 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=22 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel AppleACPICPU: ProcessorId=23 LocalApicId=0 Disabled
16.07.11 11:51:35 kernel calling mpo_policy_init for TMSafetyNet
16.07.11 11:51:35 kernel Security policy loaded: Safety net for Time Machine (TMSafetyNet)
16.07.11 11:51:35 kernel calling mpo_policy_init for Quarantine
16.07.11 11:51:35 kernel Security policy loaded: Quarantine policy (Quarantine)
16.07.11 11:51:35 kernel calling mpo_policy_init for Sandbox
16.07.11 11:51:35 kernel Security policy loaded: Seatbelt sandbox policy (Sandbox)
16.07.11 11:51:35 kernel Copyright (c) 1982, 1986, 1989, 1991, 1993
16.07.11 11:51:35 kernel The Regents of the University of California. All rights reserved.
16.07.11 11:51:35 kernel MAC Framework successfully initialized
16.07.11 11:51:35 kernel using 16384 buffer headers and 4096 cluster IO buffer headers
16.07.11 11:51:35 kernel IOAPIC: Version 0x20 Vectors 64:87
16.07.11 11:51:35 kernel ACPI: System State [S0 S3 S4 S5] (S3)
16.07.11 11:51:35 kernel PFM64 0xff10000000, 0xf0000000
16.07.11 11:51:35 kernel [ PCI configuration begin ]
16.07.11 11:51:35 kernel AppleIntelCPUPowerManagement: Turbo Ratios 0000
16.07.11 11:51:35 kernel AppleIntelCPUPowerManagement: (built 16:44:42 Jun 7 2011) initialization complete
16.07.11 11:51:35 kernel console relocated to 0xff20010000
16.07.11 11:51:35 kernel PCI configuration changed (bridge=7 device=2 cardbus=0)
16.07.11 11:51:35 kernel [ PCI configuration end, bridges 15 devices 51 ]
16.07.11 11:51:35 kernel mbinit: done (96 MB memory set for mbuf pool)
16.07.11 11:51:35 kernel rooting via boot-uuid from /chosen: 43D7E44E-35C3-3C6B-8EEB-548E43D81587
16.07.11 11:51:35 kernel Waiting on <dict ID="0"><key>IOProviderClass</key><string ID="1">IOResources</string><key>IOResourceMatch</key><string ID="2">boot-uuid-media</string></dict>com.apple.AppleFSCompressionTypeZlib kmod start
16.07.11 11:51:35 kernel 2.3.19 Little Snitch: starting
16.07.11 11:51:35 kernel com.apple.AppleFSCompressionTypeZlib load succeeded
16.07.11 11:51:35 kernel AppleIntelCPUPowerManagementClient: ready
16.07.11 11:51:35 kernel Intel82574L::staIrntt e-l 8B2u5i7l4tL ::sJtuanr t 7- 2B0u1i1l t1 6:J4u2n: 5 07 -2-0 1r1u n1n6i:n4g2 :o5n0 d-e-v ircuen naitn g on dev
16.07.11 11:51:35 kernel ice at
16.07.11 11:51:35 kernel BTCOEXIST off
16.07.11 11:51:35 kernel wl0: Broadcom BCM432b 802.11 Wireless Controller
16.07.11 11:51:35 kernel 5.10.131.42
16.07.11 11:51:35 kernel FireWire (OHCI) TI ID 823f built-in now active, GUID 70cd60fffe6d31b6; max speed s800.
16.07.11 11:51:35 kernel Got boot device = IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/SATA@1F,2/AppleAHCI/PRT2 @2/IOAHCIDevice@0/AppleAHCIDiskDriver/IOAHCIBlockStorageDevice/IOBlockStorageDri ver/WDC WD1001FALS-41Y6A0 Media/IOGUIDPartitionScheme/Customer@2
16.07.11 11:51:35 kernel BSD root: disk0s2, major 14, minor 2
16.07.11 11:51:35 kernel Kernel is LP64
16.07.11 11:51:32 com.apple.launchd[1] *** launchd[1] has started up. ***
16.07.11 11:51:32 com.apple.launchd[1] *** Verbose boot, will log to /dev/console. ***
16.07.11 11:51:36 kernel Intel82574L: Ethernet address 70:cd:60:a9:0a:c7
16.07.11 11:51:36 kernel Intel82574L: Ethernet address 70:cd:60:a8:f3:88
16.07.11 11:51:36 kernel AirPort_Brcm43224: Ethernet address c8:bc:c8:f4:bd:9dsystemShutdown false
16.07.11 11:51:36 kernel IO80211Controller::dataLinkLayerAttachComplete(): adding AppleEFINVRAM notification
16.07.11 11:51:40 bootlog[44] BOOT_TIME: 1310809891 0
16.07.11 11:51:41 mDNSResponder[32] mDNSResponder mDNSResponder-258.21 (May 26 2011 14:40:13) starting
16.07.11 11:51:43 kernel USBF: 11.997 AppleUSBHubPort: Port 2 of Hub at 0x5a100000 about to terminate a busy device (CompositeDevice) after waiting 10 seconds
16.07.11 11:51:43 kernel AirPort: Link Down on en2. Reason 1 (Unspecified).
16.07.11 11:51:43 kernel Previous Shutdown Cause: 0Waves SoundGrid Version: 2.0.0.14, Non-Interleaved Playback
16.07.11 11:51:43 kernel DSMOS has arrived
16.07.11 11:51:43 kernel ** Device in slot: SLOT-1 **
16.07.11 11:51:43 kernel 00000000 ffffffff Intel82574L::timeoutHandler - link is down
16.07.11 11:51:44 kernel Ethernet [Intel82574L]: Link up on en0, 100-Megabit, Full-duplex, Symmetric flow-control, Debug [796d,6f48,0de1,0200,45e1,4000]
16.07.11 11:51:44 configd[13] setting hostname to "Dominik-Rotherts-Mac-Pro.local"
16.07.11 11:51:44 configd[13] network configuration changed.
16.07.11 11:51:44 blued[17] Apple Bluetooth daemon started
16.07.11 11:51:44 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow[33 ] Login Window Application Started
16.07.11 11:51:44 com.apple.SecurityServer[28] Session 0x5fbff962 created
16.07.11 11:51:45 com.apple.SecurityServer[28] Entering service
16.07.11 11:51:45 com.apple.kextd[10] Can't load /System/Library/Extensions/MobileIODriver.kext - no code for running kernel's architecture.
16.07.11 11:51:45 com.apple.kextd[10] Failed to load /System/Library/Extensions/MobileIODriver.kext - (libkern/kext) requested architecture/executable not found.
16.07.11 11:51:45 com.apple.kextd[10] Load com.mhlabs.driver.MobileIOAudioDriver.10.5 failed; removing personalities.
16.07.11 11:51:45 kernel Starting: @(#)$Id: MobileIOAudioDevice.cpp 2298 2010-10-28 08:32:26Z bj $
16.07.11 11:51:45 kernel Build #: 5.4d208 [0704]
16.07.11 11:51:45 kernel Timing:-- Using Timers
16.07.11 11:51:45 kernel MobileIOAudioDevice[0xffffff80ff7fe000]::start(0xffffff8020ad9000)
16.07.11 11:51:45 kernel MobileIOAudioDevice[0xffffff80ff7fe000]::start(0xffffff8020ad9000) hwbt: 0 bt: 0 sn: 4000
16.07.11 11:51:45 kernel mCurrentClockSourceAddr: c036
16.07.11 11:51:45 kernel Firmware: 5.0.37
16.07.11 11:51:45 kernel 2dCardType: 1
16.07.11 11:51:45 kernel fDoesntNeedInputChannelFlip: 1
16.07.11 11:51:45 kernel MobileIOAudioEngine[0xffffff8021549e00]::init()
16.07.11 11:51:45 kernel New Sample Offset: 18
16.07.11 11:51:46 com.apple.kextd[10] Can't load /System/Library/Extensions/IOSerialFamily.kext/Contents/PlugIns/InternalModemSu pport.kext - no code for running kernel's architecture.
16.07.11 11:51:46 com.apple.kextd[10] Failed to load /System/Library/Extensions/IOSerialFamily.kext/Contents/PlugIns/InternalModemSu pport.kext - (libkern/kext) requested architecture/executable not found.
16.07.11 11:51:46 com.apple.kextd[10] Load com.apple.driver.InternalModemSupport failed; removing personalities.
16.07.11 11:51:47 kernel AppleTyMCEDriver::start coreVIDPID = 0x2c708086 Number of packages = 1 Number of cpus = 16 memory monitor trough PCI
16.07.11 11:51:47 configd[13] network configuration changed.
16.07.11 11:51:47 configd[13] network configuration changed.
16.07.11 11:51:47 com.apple.usbmuxd[24] usbmuxd-211 built on Feb 8 2011 at 13:49:43 on Feb 8 2011 at 13:49:43, running 64 bit
16.07.11 11:51:48 kernel Auth result for: 00:0c:f6:55:a3:8c MAC AUTH succeeded
16.07.11 11:51:48 kernel AirPort: Link Up on en2
16.07.11 11:51:49 kernel AirPort: RSN handshake complete on en2
16.07.11 11:51:52 AGProtocolService[49] Waves SG Protocol Service: Could not Start Kernel Driver Streaming!
16.07.11 11:51:54 configd[13] network configuration changed.
16.07.11 11:51:58 kernel CompositeDevice::terminate(kIOServiceSynchronous) timeout
16.07.11 11:52:02 configd[13] network configuration changed.
16.07.11 11:52:06 kernel [ffffff8021553c00][BNBTrackpadDevice::init][54] init is complete
16.07.11 11:52:06 kernel [ffffff8021553c00][BNBTrackpadDevice::probe][54] entered
16.07.11 11:52:07 kernel [ffffff8021553c00][BNBTrackpadDevice::handleStart][54] Done
16.07.11 11:52:07 kernel [ffffff8022493a00][AppleMultitouchHIDEventDriver::start] entered
16.07.11 11:52:07 kernel [ffffff80224bbc00][AppleMultitouchDevice::start] entered
16.07.11 11:52:35 configd[13] InterfaceNamer: timed out waiting for IOKit to quiesce
16.07.11 11:52:35 configd[13] InterfaceNamer: Busy services :
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1 [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0 [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/UHC6@1A,2 [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/UHC6@1A,2/AppleUSBUHCI [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/UHC6@1A,2/AppleUSBUHCI/Co mpositeDevice@5a120000 [4]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/UHC6@1A,2/AppleUSBUHCI/Co mpositeDevice@5a120000/IOUSBCompositeDriver [1]
16.07.11 11:52:35 configd[13] InterfaceNamer: MacPro5,1/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/UHC6@1A,2/AppleUSBUHCI/Co mpositeDevice@5a120000/IOUSBInterface@0 [2]
16.07.11 11:52:48 WindowServer[65] kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
16.07.11 11:52:48 com.apple.WindowServer[65] Sat Jul 16 11:52:48 Dominik-Rotherts-Mac-Pro.local WindowServer[65] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
16.07.11 11:52:49 kernel Sound assertion ""Graphics vendor supplied 'av-signal-type' property indicates a DVI device with audio capabilities has been attached but cannot be supported."" failed in AppleHDAController at line 2283 goto handler
16.07.11 11:52:49 kernel Sound assertion ""Graphics vendor supplied 'av-signal-type' property indicates a DVI device with audio capabilities has been attached but cannot be supported."" failed in AppleHDAController at line 2283 goto handler
16.07.11 11:52:49 com.apple.SecurityServer[28] Session 0x22edb7 created
16.07.11 11:52:49 com.apple.SecurityServer[28] Session 0x22edb7 attributes 0x30
16.07.11 11:52:50 loginwindow[33] Login Window Started Security Agent
16.07.11 11:52:50 SecurityAgent[106] User info context values set for Dominik
16.07.11 11:52:50 SecurityAgent[106] Login Window login proceeding
16.07.11 11:52:50 SecurityAgent[106] Login Window done
16.07.11 11:52:50 loginwindow[33] Login Window - Returned from Security Agent
16.07.11 11:52:50 loginwindow[33] USER_PROCESS: 33 console
16.07.11 11:52:50 com.apple.loginwindow[33] PING 169.254.100.231 (169.254.100.231): 56 data bytes
16.07.11 11:52:50 com.apple.loginwindow[33] 64 bytes from 169.254.100.231: icmp_seq=0 ttl=255 time=0.081 ms
16.07.11 11:52:50 com.apple.loginwindow[33] --- 169.254.100.231 ping statistics ---
16.07.11 11:52:50 com.apple.loginwindow[33] 1 packets transmitted, 1 packets received, 0.0% packet loss
16.07.11 11:52:50 com.apple.loginwindow[33] round-trip min/avg/max/stddev = 0.081/0.081/0.081/0.000 ms
16.07.11 11:52:50 com.apple.launchctl.Aqua[112] launchctl: Please convert the following to launchd: /etc/mach_init_per_user.d/com.adobe.SwitchBoard.monitor.plist
16.07.11 11:52:50 com.apple.launchd.peruser.501[90] (com.apple.ReportCrash) Falling back to default Mach exception handler. Could not find: com.apple.ReportCrash.Self
16.07.11 11:52:51 com.apple.loginwindow[33] route: writing to routing socket: No such process
16.07.11 11:52:51 com.apple.loginwindow[33] route: writing to routing socket: No such process
16.07.11 11:52:51 com.apple.loginwindow[33] route: writing to routing socket: No such process
16.07.11 11:52:57 com.apple.launchd.peruser.501[90] (com.apple.Kerberos.renew.plist[141]) Exited with exit code: 1
16.07.11 11:52:57 com.apple.launchd.peruser.501[90] (0x102300070.mach_init.switchboard.sh) Failed to check-in!
16.07.11 11:52:58 com.apple.usbmuxd[24] HandleUSBMuxDictionary client 0x101800490-iTunesHelper/com.apple.iTunesHelper using library usbmuxd-211 built on Jan 13 2011 at 04:19:31, running usbmuxd-211 built on Feb 8 2011 at 13:49:43
16.07.11 11:53:04 MIDIServer[164] MIDIServer [164] starting; arch=x86_64
16.07.11 11:53:05 MIDIServer[164] PlugIn EuphonixMIDI.plugin -- /Library/Audio/MIDI Drivers/ does not contain a supported architecture.
16.07.11 11:53:05 MIDIServer[164] MIDIServer relaunching because a 32-bit driver was found
16.07.11 11:53:06 MIDIServer[164] MIDIServer [164] starting; arch=i386
16.07.11 11:53:06 EuControl[128] CoreText: Invalid 'kern' Subtable In CTFont <name: MetaKorrespondenz-Bold, size: 26.000000, matrix: 0x0>
CTFontDescriptor <attributes: <CFBasicHash 0x2510fc0 [0xa08e8ec0]>{type = mutable dict, count = 1,
entries =>
1 : <CFString 0xa05a3d78 [0xa08e8ec0]>{contents = "NSFontNameAttribute"} = <CFString 0x2607c90 [0xa08e8ec0]>{contents = "MetaKorrespondenz-Bold"}
>
16.07.11 11:53:06 EuControl[128] EuControl finished launching...
16.07.11 11:53:06 EuControl[128] Starting EuCon...
16.07.11 11:53:08 MIOConsole[155] Open Succeeded
16.07.11 11:53:08 MIOConsole[155] Reg Session ref = 20ad7800 Session ref = 1; mIOService = 4503
16.07.11 11:53:08 MIOConsole[155] MIOAddMIOUnit: Box attached! [0] - 0x2010a00 - Mobile I/O 2882 s/n: 5
16.07.11 11:53:09 [0x0-0x17017].com.Euphonix.EuConDiscovery[170] Starting to discover, main tid:15745024
16.07.11 11:53:48 kernel npvhash=4095
16.07.11 11:53:09 [0x0-0x17017].com.Euphonix.EuConDiscovery[170] Successfully inited discovery ORBOkay, I just came a step further with troubleshooting but still hope someone may help me out of this.
Everytime I shutdown the system before the error occurs again on bootup, the shutdown messages contain something like "AppleBluetooth ..." after unmounting all disks - unfortunately I cannot find this message in the logfiles but it's there on shutdown (using verbose mode) just before the system halts. Then, the next boot will lead to the mentioned problems. If I shutdown the system and the message does not appear, everything's going to be fine on bootup.
There must be something wrong with the wireless keyboard + magic trackpad:
Jul 17 20:21:08 localhost kernel[0]: USBF: 11.976 AppleUSBHubPort: Port 2 of Hub at 0x5a100000 about to terminate a busy device (CompositeDevice) after waiting 10 seconds
Jul 17 20:21:16 Dominik-Rotherts-Mac-Pro kernel[0]: [ffffff8021462800][BNBTrackpadDevice::init][54] init is complete
Jul 17 20:21:16 Dominik-Rotherts-Mac-Pro kernel[0]: [ffffff8021462800][BNBTrackpadDevice::probe][54] entered
Jul 17 20:21:16 Dominik-Rotherts-Mac-Pro kernel[0]: 00000000 ffffffff Intel82574L::timeoutHandler - link is down
Jul 17 20:21:16 Dominik-Rotherts-Mac-Pro kernel[0]: [ffffff8021462800][BNBTrackpadDevice::handleStart][54] Done
Jul 17 20:21:16 Dominik-Rotherts-Mac-Pro kernel[0]: [ffffff802223e000][AppleMultitouchHIDEventDriver::start] entered
Jul 17 20:21:16 Dominik-Rotherts-Mac-Pro kernel[0]: [ffffff802231c100][AppleMultitouchDevice::start] entered
Jul 17 20:21:23 Dominik-Rotherts-Mac-Pro kernel[0]: CompositeDevice::terminate(kIOServiceSynchronous) timeout -
Sharepoint 2013 MP - Configuration Database connection failed
Hi all!
I run a WS2012 R2 with SCOM 2012R2. I'm trying to monitor Sharepoint 2013 Farm, with the Sharepoint 2013 MP. The Sharepoint farm and it's SQL server is on another domain, with two-way trust, and the agents are working on the Sharepoint and SQL servers.
I use SQL aliases for Sharepoint DB's, so I've made an override to the connection string to make it connect to the correct database.
The override is working fine, I can see that SCOM is trying to connect to the SQL server, but I cannot seem to make SCOM use the correct Run As account on these configuration databases. Most of the Sharepoint MP seems to be working fine, with the farm admin
account, but I don't know how I can force this override connectionString to use a specific user.
WS2012R2 with SCOM2012R2 UR3
Sharepoint 2013 Farm on WS2008R2 OS.
MS SQL 2012 on WS2008R2.
It uses the default SCOM monitoring account, instead of the Sharepoint RunAs account.
Any suggestions?
How do I make it use the correct Run As account?
(This guy has the
same problem)
Thanks,
NikolajI was looking at this issue not too long ago, and looked through the management pack xml, to see if there was a missing secure reference for DB connection monitors. I only glanced through the MP, but it looked to me as if the DB connection
monitors references the same account as the other sharepoint monitors. (Yes, that full-blown farm admin account). Again I am not sure, but it seems the management pack has trouble using the referenced RunAs account in the connection strings and then, because
the watcher node is setup default to run off the management server, it falls back to the management server action account.
You mention, that you have a two-way trust between you management group and SPS SQL servers. You could then bring this to work by granting your management server action account public rights on your configuration and content DB’s. Not
optimal, but it’s a workaround. For SPS 2013 this should work without changing the connection strings, as you would have to with SPS 2010.
I know this is not solution you’re are looking for, but it just might be enough for you to get a step further. I don’t know of any solution, so far, to get the DB connections to use the SPS RunAs account. -
PL/SQL 101 : Exception Handling
Frequently I see questions and issues around the use of Exception/Error Handling in PL/SQL. More often than not the issue comes from the questioners misunderstanding about how PL/SQL is constructed and executed, so I thought I'd write a small article covering the key concepts to give a clear picture of how it all hangs together. (Note: the examples are just showing examples of the exception handling structure, and should not be taken as truly valid code for ways of handling things)
Exception Handling
Contents
1. Understanding Execution Blocks (part 1)
2. Execution of the Execution Block
3. Exceptions
4. Understanding Execution Blocks (part 2)
5. How to continue exection of statements after an exception
6. User defined exceptions
7. Line number of exception
8. Exceptions within code within the exception block
1. Understanding Execution Blocks (part 1)
The first thing that one needs to understand is almost taking us back to the basics of PL/SQL... how a PL/SQL execution block is constructed.
Essentially an execution block is made of 3 sections...
+---------------------------+
| Declaration Section |
+---------------------------+
| Statements Section |
+---------------------------+
| Exception Section |
+---------------------------+
The Declaration section is the part defined between the PROCEDURE/FUNCTION header or the DECLARE keyword (for anonymous blocks) and the BEGIN keyword. (Optional section)
The Statements section is where your code goes and lies between the BEGIN keyword and the EXCEPTION keyword (or END keyword if there is no EXCEPTION section). (Mandatory section)
The Exception section is where any exception handling goes and lies between the EXCEPTION keyword at the END keyword. (Optional section)
Example of an anonymous block...
DECLARE
.. declarative statements go here ..
BEGIN
.. code statements go here ..
EXCEPTION
.. exception handlers go here ..
END;
Example of a procedure/function block...
[CREATE OR REPLACE] (PROCEDURE|FUNCTION) <proc or fn name> [(<parameters>)] [RETURN <datatype>] (IS|AS)
.. declarative statements go here ..
BEGIN
.. code statements go here ..
EXCEPTION
.. exception handlers go here ..
END;
(Note: The same can also be done for packages, but let's keep it simple)
2. Execution of the Execution Block
This may seem a simple concept, but it's surprising how many people have issues showing they haven't grasped it. When an Execution block is entered, the declaration section is processed, creating a scope of variables, types , cursors, etc. to be visible to the execution block and then execution enters into the Statements section. Each statment in the statements section is executed in turn and when the execution completes the last statment the execution block is exited back to whatever called it.
3. Exceptions
Exceptions generally happen during the execution of statements in the Statements section. When an exception happens the execution of statements jumps immediately into the exception section. In this section we can specify what exceptions we wish to 'capture' or 'trap' and do one of the two following things...
(Note: The exception section still has access to all the declared items in the declaration section)
3.i) Handle the exception
We do this when we recognise what the exception is (most likely it's something we expect to happen) and we have a means of dealing with it so that our application can continue on.
Example...
(without the exception handler the exception is passed back to the calling code, in this case SQL*Plus)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 begin
4 select ename
5 into v_name
6 from emp
7 where empno = &empno;
8 dbms_output.put_line(v_name);
9* end;
SQL> /
Enter value for empno: 123
old 7: where empno = &empno;
new 7: where empno = 123;
declare
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 4
(with an exception handler, we capture the exception, handle it how we want to, and the calling code is happy that there is no error for it to report)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 begin
4 select ename
5 into v_name
6 from emp
7 where empno = &empno;
8 dbms_output.put_line(v_name);
9 exception
10 when no_data_found then
11 dbms_output.put_line('There is no employee with this employee number.');
12* end;
SQL> /
Enter value for empno: 123
old 7: where empno = &empno;
new 7: where empno = 123;
There is no employee with this employee number.
PL/SQL procedure successfully completed.
3.ii) Raise the exception
We do this when:-
a) we recognise the exception, handle it but still want to let the calling code know that it happened
b) we recognise the exception, wish to log it happened and then let the calling code deal with it
c) we don't recognise the exception and we want the calling code to deal with it
Example of b)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 v_empno NUMBER := &empno;
4 begin
5 select ename
6 into v_name
7 from emp
8 where empno = v_empno;
9 dbms_output.put_line(v_name);
10 EXCEPTION
11 WHEN no_data_found THEN
12 INSERT INTO sql_errors (txt)
13 VALUES ('Search for '||v_empno||' failed.');
14 COMMIT;
15 RAISE;
16* end;
SQL> /
Enter value for empno: 123
old 3: v_empno NUMBER := &empno;
new 3: v_empno NUMBER := 123;
declare
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 15
SQL> select * from sql_errors;
TXT
Search for 123 failed.
SQL>
Example of c)
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_name VARCHAR2(20);
3 v_empno NUMBER := &empno;
4 begin
5 select ename
6 into v_name
7 from emp
8 where empno = v_empno;
9 dbms_output.put_line(v_name);
10 EXCEPTION
11 WHEN no_data_found THEN
12 INSERT INTO sql_errors (txt)
13 VALUES ('Search for '||v_empno||' failed.');
14 COMMIT;
15 RAISE;
16 WHEN others THEN
17 RAISE;
18* end;
SQL> /
Enter value for empno: 'ABC'
old 3: v_empno NUMBER := &empno;
new 3: v_empno NUMBER := 'ABC';
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at line 3
SQL> select * from sql_errors;
TXT
Search for 123 failed.
SQL>
As you can see from the sql_errors log table, no log was written so the WHEN others exception was the exception that raised the error to the calling code (SQL*Plus)
4. Understanding Execution Blocks (part 2)
Ok, so now we understand the very basics of an execution block and what happens when an exception happens. Let's take it a step further...
Execution blocks are not just a single simple block in most cases. Often, during our statements section we have a need to call some reusable code and we do that by calling a procedure or function. Effectively this nests the procedure or function's code as another execution block within the current statement section so, in terms of execution, we end up with something like...
+---------------------------------+
| Declaration Section |
+---------------------------------+
| Statements Section |
| . |
| +---------------------------+ |
| | Declaration Section | |
| +---------------------------+ |
| | Statements Section | |
| +---------------------------+ |
| | Exception Section | |
| +---------------------------+ |
| . |
+---------------------------------+
| Exception Section |
+---------------------------------+
Example... (Note: log_trace just writes some text to a table for tracing)
SQL> create or replace procedure a as
2 v_dummy NUMBER := log_trace('Procedure A''s Declaration Section');
3 begin
4 v_dummy := log_trace('Procedure A''s Statement Section');
5 v_dummy := 1/0; -- cause an exception
6 exception
7 when others then
8 v_dummy := log_trace('Procedure A''s Exception Section');
9 raise;
10 end;
11 /
Procedure created.
SQL> create or replace procedure b as
2 v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
3 begin
4 v_dummy := log_trace('Procedure B''s Statement Section');
5 a; -- HERE the execution passes to the declare/statement/exception sections of A
6 exception
7 when others then
8 v_dummy := log_trace('Procedure B''s Exception Section');
9 raise;
10 end;
11 /
Procedure created.
SQL> exec b;
BEGIN b; END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.B", line 9
ORA-06512: at line 1
SQL> select * from code_trace;
TXT
Procedure B's Declaration Section
Procedure B's Statement Section
Procedure A's Declaration Section
Procedure A's Statement Section
Procedure A's Exception Section
Procedure B's Exception Section
6 rows selected.
SQL>
Likewise, execution blocks can be nested deeper and deeper.
5. How to continue exection of statements after an exception
One of the common questions asked is how to return execution to the statement after the one that created the exception and continue on.
Well, firstly, you can only do this for statements you expect to raise an exception, such as when you want to check if there is no data found in a query.
If you consider what's been shown above you could put any statement you expect to cause an exception inside it's own procedure or function with it's own exception section to handle the exception without raising it back to the calling code. However, the nature of procedures and functions is really to provide a means of re-using code, so if it's a statement you only use once it seems a little silly to go creating individual procedures for these.
Instead, you nest execution blocks directly, to give the same result as shown in the diagram at the start of part 4 of this article.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure b (p_empno IN VARCHAR2) as
2 v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
3 begin
4 v_dummy := log_trace('Procedure B''s Statement Section');
5 -- Here we start another execution block nested in the first one...
6 declare
7 v_dummy NUMBER := log_trace('Nested Block Declaration Section');
8 begin
9 v_dummy := log_trace('Nested Block Statement Section');
10 select empno
11 into v_dummy
12 from emp
13 where empno = p_empno; -- Note: the parameters and variables from
parent execution block are available to use!
14 exception
15 when no_data_found then
16 -- This is an exception we can handle so we don't raise it
17 v_dummy := log_trace('No employee was found');
18 v_dummy := log_trace('Nested Block Exception Section - Exception Handled');
19 when others then
20 -- Other exceptions we can't handle so we raise them
21 v_dummy := log_trace('Nested Block Exception Section - Exception Raised');
22 raise;
23 end;
24 -- ...Here endeth the nested execution block
25 -- As the nested block handled it's exception we come back to here...
26 v_dummy := log_trace('Procedure B''s Statement Section Continued');
27 exception
28 when others then
29 -- We'll only get to here if an unhandled exception was raised
30 -- either in the nested block or in procedure b's statement section
31 v_dummy := log_trace('Procedure B''s Exception Section');
32 raise;
33* end;
SQL> /
Procedure created.
SQL> exec b(123);
PL/SQL procedure successfully completed.
SQL> select * from code_trace;
TXT
Procedure B's Declaration Section
Procedure B's Statement Section
Nested Block Declaration Section
Nested Block Statement Section
No employee was found
Nested Block Exception Section - Exception Handled
Procedure B's Statement Section Continued
7 rows selected.
SQL> truncate table code_trace;
Table truncated.
SQL> exec b('ABC');
BEGIN b('ABC'); END;
ERROR at line 1:
ORA-01722: invalid number
ORA-06512: at "SCOTT.B", line 32
ORA-06512: at line 1
SQL> select * from code_trace;
TXT
Procedure B's Declaration Section
Procedure B's Statement Section
Nested Block Declaration Section
Nested Block Statement Section
Nested Block Exception Section - Exception Raised
Procedure B's Exception Section
6 rows selected.
SQL>
You can see from this that, very simply, the code that we expected may have an exception was able to either handle the exception and return to the outer execution block to continue execution, or if an unexpected exception occurred then it was able to be raised up to the outer exception section.
6. User defined exceptions
There are three sorts of 'User Defined' exceptions. There are logical situations (e.g. business logic) where, for example, certain criteria are not met to complete a task, and there are existing Oracle errors that you wish to give a name to in order to capture them in the exception section. The third is raising your own exception messages with our own exception numbers. Let's look at the first one...
Let's say I have tables which detail stock availablility and reorder levels...
SQL> select * from reorder_level;
ITEM_ID STOCK_LEVEL
1 20
2 20
3 10
4 2
5 2
SQL> select * from stock;
ITEM_ID ITEM_DESC STOCK_LEVEL
1 Pencils 10
2 Pens 2
3 Notepads 25
4 Stapler 5
5 Hole Punch 3
SQL>
Now, our Business has told the administrative clerk to check stock levels and re-order anything that is below the re-order level, but not to hold stock of more than 4 times the re-order level for any particular item. As an IT department we've been asked to put together an application that will automatically produce the re-order documents upon the clerks request and, because our company is so tight-ar*ed about money, they don't want to waste any paper with incorrect printouts so we have to ensure the clerk can't order things they shouldn't.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 from stock s join reorder_level r on (s.item_id = r.item_id)
7 where s.item_id = p_item_id;
8 --
9 v_stock cur_stock_reorder%ROWTYPE;
10 begin
11 OPEN cur_stock_reorder;
12 FETCH cur_stock_reorder INTO v_stock;
13 IF cur_stock_reorder%NOTFOUND THEN
14 RAISE no_data_found;
15 END IF;
16 CLOSE cur_stock_reorder;
17 --
18 IF v_stock.stock_level >= v_stock.reorder_level THEN
19 -- Stock is not low enough to warrant an order
20 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
21 ELSE
22 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
23 -- Required amount is over-ordering
24 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
25 ELSE
26 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
27 -- Here goes our code to print the order
28 END IF;
29 END IF;
30 --
31 exception
32 WHEN no_data_found THEN
33 CLOSE cur_stock_reorder;
34 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
35* end;
SQL> /
Procedure created.
SQL> exec re_order(10,100);
Invalid Item ID.
PL/SQL procedure successfully completed.
SQL> exec re_order(3,40);
Stock has not reached re-order level yet!
PL/SQL procedure successfully completed.
SQL> exec re_order(1,100);
Quantity specified is too much. Max for this item: 70
PL/SQL procedure successfully completed.
SQL> exec re_order(2,50);
Order OK. Printing Order...
PL/SQL procedure successfully completed.
SQL>
Ok, so that code works, but it's a bit messy with all those nested IF statements. Is there a cleaner way perhaps? Wouldn't it be nice if we could set up our own exceptions...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 from stock s join reorder_level r on (s.item_id = r.item_id)
7 where s.item_id = p_item_id;
8 --
9 v_stock cur_stock_reorder%ROWTYPE;
10 --
11 -- Let's declare our own exceptions for business logic...
12 exc_not_warranted EXCEPTION;
13 exc_too_much EXCEPTION;
14 begin
15 OPEN cur_stock_reorder;
16 FETCH cur_stock_reorder INTO v_stock;
17 IF cur_stock_reorder%NOTFOUND THEN
18 RAISE no_data_found;
19 END IF;
20 CLOSE cur_stock_reorder;
21 --
22 IF v_stock.stock_level >= v_stock.reorder_level THEN
23 -- Stock is not low enough to warrant an order
24 RAISE exc_not_warranted;
25 END IF;
26 --
27 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
28 -- Required amount is over-ordering
29 RAISE exc_too_much;
30 END IF;
31 --
32 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
33 -- Here goes our code to print the order
34 --
35 exception
36 WHEN no_data_found THEN
37 CLOSE cur_stock_reorder;
38 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
39 WHEN exc_not_warranted THEN
40 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
41 WHEN exc_too_much THEN
42 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
43* end;
SQL> /
Procedure created.
SQL> exec re_order(10,100);
Invalid Item ID.
PL/SQL procedure successfully completed.
SQL> exec re_order(3,40);
Stock has not reached re-order level yet!
PL/SQL procedure successfully completed.
SQL> exec re_order(1,100);
Quantity specified is too much. Max for this item: 70
PL/SQL procedure successfully completed.
SQL> exec re_order(2,50);
Order OK. Printing Order...
PL/SQL procedure successfully completed.
SQL>
That's better. And now we don't have to use all those nested IF statements and worry about it accidently getting to code that will print the order out as, once one of our user defined exceptions is raised, execution goes from the Statements section into the Exception section and all handling of errors is done in one place.
Now for the second sort of user defined exception...
A new requirement has come in from the Finance department who want to have details shown on the order that show a re-order 'indicator' based on the formula ((maximum allowed stock - current stock)/re-order quantity), so this needs calculating and passing to the report...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
7 from stock s join reorder_level r on (s.item_id = r.item_id)
8 where s.item_id = p_item_id;
9 --
10 v_stock cur_stock_reorder%ROWTYPE;
11 --
12 -- Let's declare our own exceptions for business logic...
13 exc_not_warranted EXCEPTION;
14 exc_too_much EXCEPTION;
15 begin
16 OPEN cur_stock_reorder;
17 FETCH cur_stock_reorder INTO v_stock;
18 IF cur_stock_reorder%NOTFOUND THEN
19 RAISE no_data_found;
20 END IF;
21 CLOSE cur_stock_reorder;
22 --
23 IF v_stock.stock_level >= v_stock.reorder_level THEN
24 -- Stock is not low enough to warrant an order
25 RAISE exc_not_warranted;
26 END IF;
27 --
28 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
29 -- Required amount is over-ordering
30 RAISE exc_too_much;
31 END IF;
32 --
33 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
34 -- Here goes our code to print the order, passing the finance_factor
35 --
36 exception
37 WHEN no_data_found THEN
38 CLOSE cur_stock_reorder;
39 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
40 WHEN exc_not_warranted THEN
41 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
42 WHEN exc_too_much THEN
43 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
44* end;
SQL> /
Procedure created.
SQL> exec re_order(2,40);
Order OK. Printing Order...
PL/SQL procedure successfully completed.
SQL> exec re_order(2,0);
BEGIN re_order(2,0); END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.RE_ORDER", line 17
ORA-06512: at line 1
SQL>
Hmm, there's a problem if the person specifies a re-order quantity of zero. It raises an unhandled exception.
Well, we could put a condition/check into our code to make sure the parameter is not zero, but again we would be wrapping our code in an IF statement and not dealing with the exception in the exception handler.
We could do as we did before and just include a simple IF statement to check the value and raise our own user defined exception but, in this instance the error is standard Oracle error (ORA-01476) so we should be able to capture it inside the exception handler anyway... however...
EXCEPTION
WHEN ORA-01476 THEN
... is not valid. What we need is to give this Oracle error a name.
This is done by declaring a user defined exception as we did before and then associating that name with the error number using the PRAGMA EXCEPTION_INIT statement in the declaration section.
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
7 from stock s join reorder_level r on (s.item_id = r.item_id)
8 where s.item_id = p_item_id;
9 --
10 v_stock cur_stock_reorder%ROWTYPE;
11 --
12 -- Let's declare our own exceptions for business logic...
13 exc_not_warranted EXCEPTION;
14 exc_too_much EXCEPTION;
15 --
16 exc_zero_quantity EXCEPTION;
17 PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
18 begin
19 OPEN cur_stock_reorder;
20 FETCH cur_stock_reorder INTO v_stock;
21 IF cur_stock_reorder%NOTFOUND THEN
22 RAISE no_data_found;
23 END IF;
24 CLOSE cur_stock_reorder;
25 --
26 IF v_stock.stock_level >= v_stock.reorder_level THEN
27 -- Stock is not low enough to warrant an order
28 RAISE exc_not_warranted;
29 END IF;
30 --
31 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
32 -- Required amount is over-ordering
33 RAISE exc_too_much;
34 END IF;
35 --
36 DBMS_OUTPUT.PUT_LINE('Order OK. Printing Order...');
37 -- Here goes our code to print the order, passing the finance_factor
38 --
39 exception
40 WHEN exc_zero_quantity THEN
41 DBMS_OUTPUT.PUT_LINE('Quantity of 0 (zero) is invalid.');
42 WHEN no_data_found THEN
43 CLOSE cur_stock_reorder;
44 DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
45 WHEN exc_not_warranted THEN
46 DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
47 WHEN exc_too_much THEN
48 DBMS_OUTPUT.PUT_LINE('Quantity specified is too much. Max for this item: '
||to_char(v_stock.reorder_limit-v_stock.stock_level));
49* end;
SQL> /
Procedure created.
SQL> exec re_order(2,0);
Quantity of 0 (zero) is invalid.
PL/SQL procedure successfully completed.
SQL>
Lastly, let's look at raising our own exceptions with our own exception numbers...
SQL> ed
Wrote file afiedt.buf
1 create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
2 cursor cur_stock_reorder is
3 select s.stock_level
4 ,r.stock_level as reorder_level
5 ,(r.stock_level*4) as reorder_limit
6 ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
7 from stock s join reorder_level r on (s.item_id = r.item_id)
8 where s.item_id = p_item_id;
9 --
10 v_stock cur_stock_reorder%ROWTYPE;
11 --
12 exc_zero_quantity EXCEPTION;
13 PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
14 begin
15 OPEN cur_stock_reorder;
16 FETCH cur_stock_reorder INTO v_stock;
17 IF cur_stock_reorder%NOTFOUND THEN
18 RAISE no_data_found;
19 END IF;
20 CLOSE cur_stock_reorder;
21 --
22 IF v_stock.stock_level >= v_stock.reorder_level THEN
23 -- Stock is not low enough to warrant an order
24 [b]RAISE_APPLICATION_ERROR(-20000, 'Stock has not reached re-order level yet!');[/b]
25 END IF;
26 --
27 IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
28 -- Required amount is over-ordering
29its nice article, have put up this one the blog
site,Nah, I don't have time to blog, but if one of the other Ace's/Experts wants to copy it to a blog with reference back to here (and all due credit given ;)) then that's fine by me.
I'd go for a book like "Selected articles by OTN members" or something. Does anybody have a list of links of all those mentioned articles?Just these ones I've bookmarked...
Introduction to regular expressions ... by CD
When your query takes too long ... by Rob van Wijk
How to pipeline a function with a dynamic number of columns? by ascheffer
PL/SQL 101 : Exception Handling by BluShadow -
Hi;
Could anyone help me to convert my example code from applet to swing,please, thank
import java.awt.*;
import java.applet.*;
import java.lang.Math;
import java.awt.Font;
import java.lang.Integer;
/*** Main class == Applet ***/
public class Suffix extends Applet implements Runnable {
private Thread main;
public s_tree _tree=null;
public node nd=null;
public boolean userPause=false,resumed=false;
private String str[]={"GOOGOL$","Paused","Resumed","Compacting","Done"};
public Color bl=Color.blue,rd=Color.red;
public Font fnt;
public int mode=3,delay=3000;
private char alph[]={'$','Q','W','E','R','T','Y','U','I','O',
'P','A','S','D','F','G','H','J','K','L',
'Z','X','C','V','B','N','M'};
/*** initialisation function. It is the first Funct to be called ***/
public void init() {
// Temp data
int temp=0,nxx=30;
// Ini. of fnt , the font size + style used by this applet.
fnt=new Font("Denis",1,25);
/*** parsing command parameters ***/
// try {
//DELAY VALUE PARAM
String param=getParameter("DELAY");
if (param!=null) {
temp=Integer.parseInt(param);
if ((temp>500)&&(temp<6000)) delay=temp;
//x LEFTMOST coordinate
param=getParameter("X");
if (param!=null) {
temp=Integer.parseInt(param);
nxx=temp;
//Base String parameter
param=getParameter("STRING");
if ((param!=null)&&(param.length()<15)) {
str[0]=param;
// } catch (ParseException e) { showParseError(e); }
// Allocating mem for _tree + initialize it .
_tree=new s_tree(str[0],fnt);
// Override xx (left_bound) by the caller's or the default value
_tree.xx=nxx;
/*** "animation loop is controled here" ***/
public void run() {
while(true) {
try {
//delay the process for time==delay
Thread.sleep(delay);
} catch (InterruptedException e) {}
//controls animation loop
repaint();
/*** override APPLET's paint function ***/
public void paint (Graphics g) {
//Output graphics
update(g);
/*** Updates the graphics ***/
public void update (Graphics g) {
// Set font
if (g.getFont()!=fnt) g.setFont(fnt);
if ((userPause==false)&&(resumed==false)) // Is the applet paused ?
g.clearRect(0,0,1024,768); //clears the screen
if (_tree==null) { // if tree is not initialised
init();
//_tree.show(g);
} else {
if (mode==3) { // if graphics output mode is 3
if (nd!=null) nd._to_rd(false);
nd=_tree.step_compact(nd); //compacts the tree one step further
if (nd==null) // if tree is totally compacted ...
mode=4; //change the ani. mode to 4 (don't call compact)
else
nd._to_rd(true); //colors the next node to compact in red
// Draw the "titleviewport's" comment
g.setColor(bl);
g.drawString(str[mode],10,15);
_tree.show(g); //show tree
} else {
g.clearRect(0,0,200,25); //clears the "titleviewport to update it"
g.setColor(rd);
if (resumed==true){
resumed=false;
g.drawString(str[2],10,15);
else g.drawString(str[1],10,15);
/*** restart the animation process ***/
public void start() {
main=new Thread(this);
main.start();
/*** stops the animation ***/
public void stop() {
main.stop();
main=null;
/*** Handles the user's events (mouse , kbd , ... ***/
public boolean handleEvent(Event evt) {
if (evt.id==Event.MOUSE_DOWN) { //if mouse button have been pushed ...
if (main!=null && main.isAlive()) {
if (userPause) {
main.start();
resumed=true;
} else {
main.stop();
userPause= !userPause;
} else {
main= new Thread(this);
main.start();
userPause=false;
resumed=true;
repaint();
return true;
} else {
return super.handleEvent(evt);
/*** Linked List of node(s) ***/
class nodelist{
nodelist next=null;
node ptr=null;
public void nodelist(){};
/*** node of a structure tree ***/
class node {
// Relatives
public nodelist children=null;
public node parent=null;
// variables
public int maxchild=12,childnum=0,level=0;
public int center[]={0,0};
public int xlen=20,ylen=10,vspace=15,hspace=8;
public int x[]={0,0};
public boolean _ishidden=false;
private Color bk=Color.black,wh=Color.white,rd=Color.red;
// Node==red toggle variable
public boolean to_rd=false;
// node's text
public String label=null;
/*** initialisation of the node ***/
public node(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,String nstr){
x[0]=nx; x[1]=ny;
xlen=nxl; ylen=nyl;
parent=nparent;
level=nlevel;
label=new String(nstr);
children=new nodelist();
/*** destroys the node ***/
public void destruct() {
// NOTE : not like C++ destructors . Do not confuse .
delete_subtree();
children=null;
parent=null;
bk=wh=rd=null;
label=null;
/*** Node to red toggle switch ***/
public void _to_rd(boolean b) {to_rd=b;};
/*** Adds a child to this node ***/
public void add_child(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
String nstr) {
if (childnum<maxchild) { // if 'legal' space left ...
if (children==null) { // if no nodelist attached ...
children=new nodelist(); //init. children
children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create node
childnum++;
} else {
nodelist dummy=children;
// search for the last nodelist
while (dummy.next!=null) dummy=dummy.next;
dummy.next=new nodelist(); //adds a nodelist
dummy=dummy.next;
dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create child
childnum++;
// Tree needs to be realigned
/*** adds a child and returns its address ***/
public node add_child_ret(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
String nstr) {
if (childnum<maxchild) {
if (children==null) {
children=new nodelist();
children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
childnum++;
return(children.ptr);
} else {
nodelist dummy=children;
// search for the last child
while (dummy.next!=null) dummy=dummy.next;
dummy.next=new nodelist();
dummy=dummy.next;
dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
childnum++;
return(dummy.ptr);
return(null);
// Tree needs to be realigned
/*** adds the node nchild as a new children ***/
public void add_child(node nchild) {
nodelist dummy=null;
dummy=children;
if (childnum<maxchild) {
if (children==null) {
children=new nodelist();
children.ptr=nchild;
childnum++;
} else {
while (dummy.next!=null) dummy=dummy.next;
dummy.next=new nodelist();
dummy=dummy.next;
dummy.ptr=nchild;
childnum++;
//Tree needs to restructured.
/*** deletes all childrens ***/
public void delete_subtree() {
while (childnum>0 && children!=null) { //while child exists , kill it
if (children.ptr!=null) {
children.ptr.destruct();
children.ptr=null;
children=children.next;
} else children=null;
childnum--;
/*** moves this node and its children horizontally ***/
public void move_tree(int nx) {
nodelist dummy=children;
x[0]+=nx;
while (childnum>0 && dummy!=null) {
if (dummy.ptr!=null) {
dummy.ptr.move_tree(nx);
dummy=dummy.next;
/*** removes the node from the tree (do not preserve order of ordered tree ) ***/
public void remove_node() {
nodelist dummy=children;
while(dummy!=null) {
if (dummy.ptr!=null){
parent.add_child(dummy.ptr);
dummy=dummy.next;
children=null;
//could call restructure tree here .
//don't forget to change the node's levels !!!
/*** show all nodes ***/
public void show_all(Graphics g) {
if (_ishidden==false) { //if not hidden
if (children!=null) { //if child exist
nodelist dummy=children; //temp var.
while(dummy!=null) { //while there is a child...
if (dummy.ptr!=null)
dummy.ptr.show_all(g);
dummy=dummy.next;
show_node(g);
/*** show nodes in preorder ***/
public int preorder_show(Graphics g,int label){
if (_ishidden==false) {
show_node(g/*,label++*/);
if (children!=null) {
nodelist dummy=children;
while(dummy!=null) {
if (dummy.ptr!=null) label=dummy.ptr.preorder_show(g,label);
dummy=dummy.next;
return(label);
/** show nodes in postorder ***/
public int postorder_show(Graphics g,int label){
if (_ishidden==false) {
if (children!=null) {
nodelist dummy=children;
while(dummy!=null) {
if (dummy.ptr!=null) label=dummy.ptr.postorder_show(g,label);
dummy=dummy.next;
show_node(g/*,label++*/);
return(label);
/*** show nodes in inorder ***/
public int inorder_show(Graphics g,int label){
if (_ishidden==false) {
if (children!=null) {
nodelist dummy=children;
if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
dummy=dummy.next;
show_node(g/*,label++*/);
while(dummy!=null) {
if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
dummy=dummy.next;
} else show_node(g/*,label++*/);
return(label);
/*** Restructure the coordinates of all nodes ***/
public int align(int min,Font fnt,int lev,Graphics g){
int i=min; //left bound
FontMetrics fntm=g.getFontMetrics(fnt); //used to know the text size
level=lev;
// node x and y radius are computed here
xlen=4+(int)(fntm.stringWidth(label)/2);
ylen=4+(int)(fntm.getHeight()/2);
if (children!=null) { //if child present ...
nodelist dummy=children;
while(dummy!=null) {
if (dummy.ptr!=null) i=dummy.ptr.align(i,fnt,lev+1,g); //align them
dummy=dummy.next;
x[0]=min+(int)((i-min)/2); //could be underflow so will be checked
x[1]=lev*(vspace+(ylen*2))+26;
// overflow should happen only when the parent node is larger than its children
if ((x[0]-xlen)<min) { //check uf underflow occurs.
move_tree(min+xlen-x[0]+1);
i=x[0]+xlen+5;
if (childnum==0) x[0]+=2;
return(i);
/*** returns the child following nd ***/
/*** if nd==null -> return 1st child ***/
/*** if nd==last children -> return null***/
public node next_child(node nd) {
nodelist dummy=null;
if (children==null) return(null);
if (nd==null) return(children.ptr);
dummy=children;
while (dummy.ptr!=nd) {
if (dummy.next!=null)
dummy=dummy.next;
else
return(null);
dummy=dummy.next;
if (dummy!=null) return(dummy.ptr);
else return(null);
/*** returns child with first letter==nh ***/
public node get_childd(char ch) {
nodelist dummy=null;
dummy=children;
while (dummy!=null) {
if (dummy.ptr!=null) {
if (dummy.ptr.label.charAt(0)==ch)
return(dummy.ptr);
dummy=dummy.next;
return(null);
/*** returns the nodelist containing nd ***/
public nodelist get_child(node nd) {
nodelist dummy=children;
while (dummy!=null) {
if (dummy.ptr==nd) return(dummy);
dummy=dummy.next;
return(null);
/*** outputs the node to Screen ***/
public void show_node(Graphics g) {
if (_ishidden==false) {
if (level>0) { //if it is not a root then draw link-line
g.setColor(bk);
g.drawLine(x[0],x[1]-ylen,parent.x[0],parent.x[1]+parent.ylen); //from this node to parent node
if (to_rd==false)
g.setColor(wh);
else
g.setColor(rd);
g.fillOval(x[0]-xlen,x[1]-ylen,xlen*2,ylen*2); //draws an oval
g.setColor(bk);
g.drawString(label,x[0]-xlen+4,x[1]+ylen-12); //output the text
/*** class which uses nodes to create a SUFFIX TREE ***/
class s_tree {
node root=null; // root node.
String str=null; // 'search' string
Font fnt=null; // font type
int xx=30; // left limit for graphics
/*** initialize a SUFFIX TREE with string==nstr and Font==nfnt ***/
public s_tree(String nstr,Font nfnt) {
str=new String(nstr);
fnt=nfnt;
create();
/*** uninitialize the structure **/
public void destruct() {
root.destruct();
str=null;
fnt=null;
/*** show the tree ***/
public void show(Graphics g) {
root.align(xx,fnt,0,g); // restructure node's coordinates
root.show_all(g); //show tree
/*** creates a tree structure from String=str ***/
public void create() {
node dummy=null;
root=new node(0,0,0,0,dummy,0," "); //create root
root.parent=null; //just to make sure ...
for (int i=0;i<str.length();i++) {
// Create subtree of root in the following way :
// create subtree ("ASDF$");
// " " ("aSDF$");
// " " ("asDF$"); ...
// where : the UPPERCASE letters is the part of the string sent to insert_string
insert_string(str.substring(i));
//root.align(0,fnt,0); //align root now ?
/*** creates a subtree of ROOT with String=nstr ***/
public void insert_string(String nstr) {
node dummy2=null,dummy=null;
int i=0;
dummy=root;
dummy2=root;
// As long as a children of dummy2 have the letter nstr[i] , dummy==thischildren
// It is used to make sure that a node does not have two children with the
// same letter
while (dummy2!=null) {
dummy2=dummy2.get_childd(nstr.charAt(i));
if (dummy2!=null) {
i++;
dummy=dummy2;
//create the nodes for the rest of the string
for(;i<nstr.length();i++) {
if (dummy!=null) dummy=dummy.add_child_ret(0,0,0,0,dummy,1,nstr.substring(i,i+1));
// Compacts the tree node by node and returns the next node to compact
// if node==null , compacts the first node ...
//Works in POST-ORDER
public node step_compact(node nd) {
node dummy=nd,dummy2=null;
nodelist ndlst=null;
// GOES TO THE LOWER LEFT CHILDREN
if (nd==null) { //first call !
dummy=root;
while(dummy.children!=null) {
if (dummy.children.ptr==null)
dummy.children=dummy.children.next;
else
dummy=dummy.children.ptr;
//*** tries to find a 'compactable' node ***
//*** It uses the POST-ORDER method ***
// if this node is not the last children then try to find next compactable node
// in the next children.
if (dummy.parent.childnum!=1) dummy=next_chain(dummy);
if (dummy==null) return(null); //fully optimized
//remove parent node.
/*** THIS IS WHERE COMPACTING TAKES PLACE **/
dummy2=dummy.parent.parent;
ndlst=dummy2.get_child(dummy.parent);
if (ndlst==null) return(null); //we've got a beeeeg problem if this happens ...
//*** merges the parent string with this one and delete parent .
dummy.label=dummy.parent.label.concat(dummy.label);
ndlst.ptr=dummy;
//delete parent .
dummy.parent=null;
dummy.parent=dummy2;
// root.align(0,fnt,0);
return(dummy);
/*** finds the next chain in the tree (i.e. the next compactable node) ***/
public node next_chain(node nd){
node dummy=null;
if (nd.parent==null) return(null); //finished ! This is the root
if (nd.parent.childnum==1) return(nd); //can be optimized
// finds the nd.parent's child following nd
dummy=nd.parent.next_child(nd);
if (dummy==null) // if OLD_nd==last child
return(next_chain(nd.parent)); //tries to find a chain upwards
else {
// OLD_nd was not the last child . nd==OLD_nd's next brother
// GOES TO THE LOWER LEFT most child of nd's subtree.
while(dummy.children!=null) {
if (dummy.children.ptr==null)
dummy.children=dummy.children.next;
else
dummy=dummy.children.ptr;
return(next_chain(dummy)); // returns the next compactable node
};First, show me the rupees! Show me the rupees!
Maybe you are looking for
-
How do you modify the web.xml to lock down the pages from a user role
how do you modify the web.xml to lock down the pages from a user role
-
How to determine the JDK version required to use a jar?
Hi all. I am using a hosted server that uses JDK 1.4.2 and I cannot upgrade the VM. I have been finding it extremely difficult to install web applications on this server since I find that after installing the app, the web server complains the bytecod
-
Has anyone ever got correct prints from the Canon CP series?
CP-220 printer. Prints fine right from my Canon camera, but from iPhoto, I never get borderless, centered prints. This is a 4x6 dye-sub printer. So after wrangling with all the settings in the page setup, print boxes, etc., the prints still don't fil
-
GreenPower battery saving app and "my Xperia" service
I have recently migrated from an iPhone to Sony Z1 on EE, and I have been pretty happy with this transition. The only thing I have noticed is that the Stamina mode was not performing as I was hoping, so I downloadd a third party battery saving app ca
-
CS6 Bridge freezes with a cache problem Windows 7
I get a pop up when bridge starts,its someyhing new. It says Bridge encountered a problem and is unable to read cache.Please try purging the central cache in Cache Preferences to correct the situation. I do that and Bridge just freezes. Do I need to