📄 resin-ejb.xtp
字号:
public String hello() { return "hello, world"; }}</example></s2><s2 title="@DenyAll"><p><code>@DenyAll</code> annotation marks a method as forbidden to allusers.</p><def title="javax.annotation.security.DenyAll">@Target({METHOD})@Retention(RetentionPolicy.RUNTIME)public @interface DenyAll {}</def></s2><s2 title="@Interceptor"><p><code>@Interceptor</code> marks a class as an interceptor usingWebBeans-style interception. The class will normally also havean <code>@AroundInvoke</code> method as well as any<code>InterceptorBindingType</code> annotations.</p><def title="javax.webbeans.Interceptor">@Target({TYPE})@Retention(RUNTIME)public @interface Interceptor {}</def></s2><s2 title="@InterceptorBindingType"><p><code>@InterceptorBindingType</code> is a WebBeans meta-annotation forcreating interceptor binding types. Applications will use<code>@InterceptorBindingType</code> to create application-specificinterceptors. The WebBeans-style of interception decouples theinterception declaration from the interceptor classes, in contrastwith the EJB-style which specifies the interceptor class directly.</p><def title="javax.webbeans.InterceptorBindingType">@Target({TYPE})@Retention(RUNTIME)public @interface InterceptorBindingType {}</def></s2><s2 title="@Interceptors"><p><code>@Interceptors</code> marks an method or class as beingintercepted by the named classes. The interceptor classes willimplement an <code>@AroundInvoke</code> method to process the<code>InvocationContext</code>.</p><deftable title="@Interceptors properties"><tr> <th>Value</th> <th>Meaning</th> <th>Default</th></tr><tr> <td>value</td> <td>Lists the interceptor classes to apply to the method.</td></tr></deftable><def title="javax.interceptor.Interceptors">@Target({TYPE,METHOD})@Retention(RUNTIME)public @interface Interceptors { public Class []value();}</def><example title="Example: @Interceptor method">import javax.interceptor.*;public class MyBean { @Interceptors(MyInterceptor.class) public String hello() { return "hello, world"; }}public class MyInterceptor { @AroundInvoke protected Object log(InvocationContext cxt) throws Exception { System.out.println("Before: " + cxt.getMethod()); Object value = cxt.proceed(); System.out.println("After: " + cxt.getMethod()); return value; }}</example></s2><s2 title="InvocationContext"><p>The <code>InvocationContext</code> API is used by invocationmethods to examine the calling context, and possibly set parameters.A no-op interceptor would just call the <code>proceed()</code> method.</p><deftable title="InvocationContext methods"><tr> <th>Method</th> <th>Description</th></tr><tr> <td>getContextData</td> <td>Returns a map containing any context information</td></tr><tr> <td>getMethod</td> <td>Returns the called API method</td></tr><tr> <td>getParameters</td> <td>Returns the Java parameters for the call</td></tr><tr> <td>getTarget</td> <td>Returns the target object, i.e. the Java object that willreceive the call after all the interceptors complete.</td></tr><tr> <td>proceed</td> <td>Call the next interceptor in the chain, or call the final objectat the end of the chain.</td></tr><tr> <td>setParameters</td> <td>Sets the Java parameters for the call</td></tr></deftable><def title="javax.interceptor.InvocationContext">public interface InvocationContext { public Object proceed() throws Exception; public Map<String, Object> getContextData(); public Method getMethod(); public Object[] getParameters() throws IllegalStateException; public void setParameters(Object[] parameters) throws IllegalStateException; public Object getTarget();}</def></s2><s2 title="@PermitAll"><p><code>@PermitAll</code> annotation marks a method as allowed for allusers.</p><def title="javax.annotation.security.PermitAll">@Target({METHOD})@Retention(RetentionPolicy.RUNTIME)public @interface PermitAll {}</def></s2><s2 title="@RolesAllowed"><p><code>@RolesAllowed</code> lists all the roles (i.e. permissions) allowedto access the method. If the user in the security context does not matchthe role, an exception will be thrown.</p><deftable title="RolesAllowed properties"><tr> <th>Value</th> <th>Meaning</th> <th>Default</th></tr><tr> <td>value</td> <td>Lists the roles (permissions) that are allowed.</td></tr></deftable><def title="javax.annotation.security.RolesAllowed">@Target({TYPE,METHOD})@Retention(RetentionPolicy.RUNTIME)public @interface RolesAllowed { String []value();}</def></s2><s2 title="@RunAs"><p><code>@RunAs</code> changes the security context user to a definedrole. Security tests within the context of the <code>@RunAs</code> willmatch the specified role.</p><deftable title="RunAs properties"><tr> <th>Value</th> <th>Meaning</th> <th>Default</th></tr><tr> <td>value</td> <td>The role name to run as.</td></tr></deftable><def title="javax.annotation.security.RunAs">@Target({TYPE})@Retention(RetentionPolicy.RUNTIME)public @interface RunAs { String value();}</def></s2><s2 title="@TransactionAttribute"><p>Defines the transaction boundary for business methods. Thedefault value is REQUIRED. If @TransactionAttribute annotates the class,it defines the default value. </p><p>All Resin-managed beans can use <code>@TransactionAttribute</code>:@Stateful, @Stateless, @MessageDriven and plain Java beans.</p><deftable title="TransactionAttributeType"><tr> <th>Value</th> <th>Meaning</th></tr><tr> <td>REQUIRED</td> <td>Start a new transaction if necessary</td></tr><tr> <td>SUPPORTS</td> <td>Don't start a new transaction, but use one if it exists</td></tr><tr> <td>MANDATORY</td> <td>Require the caller to have started a transaction</td></tr><tr> <td>NEVER</td> <td>Forbid the caller to have started a transaction</td></tr><tr> <td>REQUIRESNEW</td> <td>Always start a new transaction, suspending the old one</td></tr><tr> <td>NOTSUPPORTED</td> <td>Suspend any active transaction</td></tr></deftable><ul><li>SUPPORTS is typically used for read-only methods</li><li>REQUIRED is typically used for updating (read/write) methods</li></ul><def title="javax.ejb.TransactionAttribute">@Target({TYPE,METHOD})@Retention(RUNTIME)public @interface TransactionAttribute { TransactionAttributeType value() default REQUIRED;}</def></s2></s1><s1 title="Dependency Injection Annotations"><s2 title="@EJB" type="defun"><p>Configures an EJB values for a field or method.</p><p>@EJB is essentially a @Resource where it's known that theresult is an EJB interface.</p><deftable-childtags><tr><td>jndiName</td><td>The jndi name of the resource</td><td>The field name</td></tr></deftable-childtags><def title="javax.ejb.EJB">@Target({TYPE, METHOD, FIELD, PARAMETER})@Retention(RUNTIME)public @interface EJB { String name() default ""; String businessInterface() default ""; String jndiName() default "";}</def><p>In the following exaple, Resin will call <code>setFoo</code>method with the bean in "java:comp/env/ejb/foo" before thesession is started.</p><example title="Example: @EJB method injection">@EJBvoid setFoo(example.Test test){ _test = test;}</example></s2><s2 title="@Resource" type="defun"><p><code>@Resource</code> provides JNDI-based resource injection.<code>@Resource</code> can also be used at the Class level todeclare a dependency in cases where the session bean loads theJNDI value by itself.</p><p>In general, it's better to use the WebBeansannotations: <code>@In</code>, <code>@Named</code>or custom <code>@BindingType</code> annotations, since they use thetype-safe WebBeans registry instead of JNDI. <code>@Resource</code>is supported for backwards compatibility.</p><deftable-childtags><tr> <th>Property</th> <th>Description</th> <th>Default</th></tr><tr> <td>authenticationType</td> <td>What kind of authentication is expected for the resource: APPLICATION orCONTAINER</td> <td>CONTAINER</td></tr><tr> <td>description</td> <td>An optional description of the resource</td> <td></td></tr><tr> <td>name</td> <td>The jndi-name of the resource</td> <td>java:comp/env/<var>class-name</var>#<var>field-name</var></td></tr><tr> <td>type</td> <td>The class of the expected resource</td> <td>The field type</td></tr><tr> <td>shareable</td> <td>True if the bean follows JCA shareability requirements.</td> <td>true</td></tr><tr> <td>mappedName</td> <td>The produce-specific name of the resource</td> <td>The field name</td></tr></deftable-childtags><def title="javax.ejb.Resource">@Target({TYPE, METHOD, FIELD, PARAMETER})@Retention(RetentionPolicy.RUNTIME)public @interface Resource { AuthenticationType authenticationType() CONTAINER; String description() default ""; String mappedName() default ""; String name() default ""; boolean shareable() default true; Class<?> type() default Object.class;}</def><p>In the following exaple, Resin will call <code>setDataSource</code>method with the data source in "java:comp/env/jdbc/test" before thesession is started. The "java:comp/env/jdbc" full nameis inferred from the DataSource type.</p><deftable title="default JNDI names"><tr> <th>Resource Type</th> <th>JNDI Prefix</th></tr><tr> <td>javax.sql.DataSource</td> <td>java:comp/env/jdbc</td></tr><tr> <td>javax.mail.*</td> <td>java:comp/env/mail</td></tr><tr> <td>javax.ejb.EntityManager</td> <td>java:comp/EntityManager</td></tr><tr> <td>javax.transaction.UserTransaction</td> <td>java:comp/UserTransaction</td></tr><tr> <td>javax.ejb.EJBHome</td> <td>java:comp/env/ejb</td></tr><tr> <td>javax.jms.*</td> <td>java:comp/env/jms</td></tr></deftable><example>@Resource(name="test")void setDataSource(javax.sql.DataSource dataSource){ _dataSource = dataSource;}</example></s2></s1> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -