KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > metadata > ConstructorConfig


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.metadata;
23
24 import javassist.CtConstructor;
25 import javassist.NotFoundException;
26 import org.jboss.aop.util.XmlHelper;
27 import org.w3c.dom.Element JavaDoc;
28
29 import java.lang.reflect.Constructor JavaDoc;
30 import java.util.Iterator JavaDoc;
31 /**
32  * The combination of the method-permission, container-transaction
33  *
34  * <p>
35  * The method-permission element specifies that one or more security
36  * roles are allowed to invoke one or more enterprise bean methods. The
37  * method-permission element consists of an optional description, a list
38  * of security role names, or an indicator to specify that the methods
39  * are not to be checked for authorization, and a list of method elements.
40  * The security roles used in the method-permission element must be
41  * defined in the security-role element of the deployment descriptor,
42  * and the methods must be methods defined in the enterprise bean�s component
43  * and/or home interfaces.
44  * </p>
45  *
46  * @author <a HREF="mailto:sebastien.alborini@m4x.org">Sebastien Alborini</a>
47  * @author <a HREF="mailto:Scott.Stark@jboss.org">Scott Stark</a>.
48  * @version $Revision: 37406 $
49  */

50 public class ConstructorConfig
51 {
52    String JavaDoc signature = null;
53    // Constructors --------------------------------------------------
54
public ConstructorConfig()
55    {
56    }
57
58    // Public --------------------------------------------------------
59

60    public boolean patternMatches(Constructor constructor)
61    {
62       // the wildcard matches everything
63
if (signature.equals("*"))
64       {
65          return true;
66       }
67
68       String JavaDoc sig = MethodConfig.getSignature(constructor.getParameterTypes());
69       return sig.equals(signature);
70    }
71
72    public boolean patternMatches(CtConstructor constructor) throws NotFoundException
73    {
74       // the wildcard matches everything
75
if (signature.equals("*"))
76       {
77          return true;
78       }
79
80       String JavaDoc sig = MethodConfig.getSignature(constructor.getParameterTypes());
81       return sig.equals(signature);
82    }
83
84    /**
85     * @param a method element
86     */

87    public void importXml(Element JavaDoc element)
88       throws Exception JavaDoc
89    {
90       Element JavaDoc paramsElement = XmlHelper.getOptionalChild(element, "constructor-params");
91       if (paramsElement == null)
92       {
93          String JavaDoc content = XmlHelper.getElementContent(element);
94          if (content == null || !content.equals("*")) throw new RuntimeException JavaDoc("Empty <constructor> element must have at least an empty <constructor-params> element");
95          signature = "*";
96          return;
97       }
98       signature = "(";
99       Iterator JavaDoc paramsIterator = XmlHelper.getChildrenByTagName(paramsElement,
100                                                                "constructor-param");
101       while (paramsIterator.hasNext())
102       {
103          signature += XmlHelper.getElementContent((Element JavaDoc)paramsIterator.next()).trim();
104          signature += " ";
105       }
106       signature += ")";
107    }
108
109 }
110
Popular Tags