In a surprise move, a judge on Friday rejected Madonna's request to adopt a second child from Malawi and said it would set a dangerous precedent to bend rules requiring that prospective parents live here for some period.

Madonna's lawyer, Alan Chinula, said later Friday that he has "filed notice for appeal in the Supreme Court of Appeal." He says no date was immediately set.

The country's child welfare minister had come out Thursday in support of the pop superstar's application to adopt 3-year-old Chifundo "Mercy" James.

PHOTOS: Click here for photos of Madonna in Malawi.

But in a lengthy ruling Friday, Judge Esme Chombo sided with critics who have said exceptions should not be made for the star who has set up a major development project for this impoverished, AIDS-stricken southern African country.

There was no immediate comment from Madonna or her spokeswoman in New York.

Chombo said other foreigners have adopted children from Malawi, but the only case in which the residency requirement was waived was to allow Madonna to take David Banda out of the country in 2006 before that adoption was finalized in 2008.

She indicated concern that doing so again could set a precedent that might eventually jeopardize children.

"It is necessary that we look beyond the petitioner ... and consider the consequences of opening the doors too wide," the judge said. "By removing the very safeguard that is supposed to protect our children, the courts ... could actually facilitate trafficking of children by some unscrupulous individuals."

The judge made clear she was not questioning Madonna's intentions, and even praised the "noble" work Madonna's charity has done to feed, educate and provide medical care for some of Malawi's more than 1 million orphans.

RELATED: Are Celebrities Overlooking American Children?

The judge said it was "my prayer" that the 3-year-old girl Madonna wanted to adopt would benefit from such programs.

Chombo said the girl Madonna wants to adopt was receiving "suitable" care in an orphanage. The judge said that contrasted with David's situation in 2006, when an orphanage was preparing to return the boy to his father, who had said he was struggling to care for him.

Madonna first traveled to Malawi in 2006 while filming a documentary on the devastating poverty and AIDS crisis, and later decided to adopt children from the country.

After the ruling Friday, journalists saw Madonna, looking relaxed and even cheerful, touring a village near Lilongwe, where she is building a school. She did not speak to reporters.

In a 2008 interview with The Associated Press, Madonna acknowledged the difficulties in adopting from Malawi, saying: "They are still trying to finesse the laws."

Chombo acknowledged the rules for foreigners were vague. Regulations that require Malawian welfare officials to observe prospective Malawian parents with the children they want to adopt for 18-24 months have been assumed to apply to foreigners, though legislation has been proposed making the period for foreigners one year.

The judge said Madonna had last visited Malawi in 2008, and "jetted into the country during the weekend just days prior to the hearing of this application."

"In my opinion, this would completely remove (Madonna) from the definition of 'resident,"' the judge said.

Critics had accused Madonna of using her fame and money to fast-track the adoption, but the singer said she had followed standard procedures. She faced similar allegations when she brought home David, who is now 3.

Mavuto Bamusi, an official with Malawi's Human Rights Consultative Committee, called Friday's ruling "a defining moment for child protection." Bamusi's group had been among those criticizing Madonna's adoption plans, saying they revealed weaknesses in the country's laws.

"We sympathize with children like Mercy who find themselves in orphanhood," Bamusi said. "But the Malawi authorities should take this as a moment of reflection. The laws of Malawi should now be strengthened so that no celebrity, no family that is trying to adopt should be seen as taking advantage of our weak laws."

In court papers made public Friday, Madonna said Chifundo's grandmother was unable to care for her. Media in the country had reported that the grandmother had initially opposed the adoption but later agreed.

The girl's mother, according to the affidavit, died at age 14 not long after her baby was born Jan. 22, 2006. There was no mention of the father in the affidavit. The mother's brother is listed as having consented to the adoption.

Malawi's child welfare minister had endorsed Madonna's adoption application.

"We have close to 2 million orphans in Malawi who need help," Women and Child Welfare Development Minister Anna Kachikho told The Associated Press. "We can't look after all of them as a country. If people like Madonna adopt even one such orphan, it's one mouth less we have to feed."

Orphans usually are taken in by their extended families in Africa, but AIDS and other diseases have taken a toll on those who might have traditionally provided support. In villages across the continent, frail elderly grandmothers do their best to care for children, but many end up in orphanages or on the streets.

Malawi, with a population of 12 million, is among the poorest countries in the world, with rampant disease and hunger, aggravated by periodic droughts and crop failure.

The U.N. says 1 million Malawian children have lost one or both parents, about half of them to AIDS, and estimates 18 million African children will have lost a parent to AIDS by 2010.

Adoptions from Africa have risen in recent years, but the continent still accounts for only about 14 percent of overseas adoptions by Americans. According to the U.S. State Department, 2,399 visas were issued to African children adopted by Americans last year, out of 17,438 adoptions from abroad. Most of the African children were from Ethiopia. Malawi, perhaps because its laws on foreign adoptions are vague, has not been a source of many children.