alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Commons Attributes example source code file (RuntimeSample.java)

This example Commons Attributes source code file (RuntimeSample.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Commons Attributes tags/keywords

beanattribute, class, class, dependency, dependency, error, exception, object, runtimeattributerepository, runtimeattributerepository, sampleifjoin, threadsafe, threadsafe, unable

The Commons Attributes RuntimeSample.java source code

/*
 * Copyright 2003-2004 The Apache Software Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.attributes.test.samples;

import org.apache.commons.attributes.Attributes;
import org.apache.commons.attributes.RuntimeAttributeRepository;

public class RuntimeSample extends SuperSample implements SampleIFJoin {
    
    static {
        try {
            RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.class);
            rar.addClassAttribute (new ThreadSafe ());
            rar.addClassAttribute (new Dependency ( SampleService.class, "sample" ));
            
            rar.addFieldAttribute ("field", new ThreadSafe ());
            
            rar.addMethodAttribute ("someMethod", new Class[]{}, new Dependency ( SampleService.class, "sample-some-method1" ));
            
            rar.addParameterAttribute ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE }, 1, new ThreadSafe ());
            rar.addReturnAttribute ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE }, new Dependency ( SampleService.class, "sample-return" ));
            
            rar.addMethodAttribute ("someMethod", new Class[]{ Integer.TYPE }, new Dependency ( SampleService.class, "sample-some-method2" ));
            
            BeanAttribute ba = new BeanAttribute (1, "a");
            ba.setAnotherNumber (56 - 14);
            ba.setName ("Smith, John \"Agent\"");
            rar.addMethodAttribute ("methodWithNamedParameters", new Class[]{}, ba);
            
            rar.addMethodAttribute ("privateMethod", new Class[]{}, new Dependency ( SampleService.class, "sample-privateMethod" ));
            
            Attributes.setAttributes (rar);
        } catch (Exception e) {
            throw new Error ("Unable to set attribute information: " + e.toString ());
        }
    }
    
    public Object field;
    
    public Object noAttributesInSubClass;
    
    public void someMethod () {
        
    }

    public Integer methodWithAttributes (int param1, int param2) {
        return null;
    }
    
    public void someMethod (int parameter) {
        
    }
    
    public void methodWithNamedParameters () {
        
    }
    
    public void methodWithNoAttributes () {
    }
    
    private void privateMethod () {
    }
    
    public static class InnerSample {
        static {
            try {
                RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.InnerSample.class);
                rar.addClassAttribute (new Dependency ( SampleService.class, "inner-sample" ));
                Attributes.setAttributes (rar);
            } catch (Exception e) {
                throw new Error ("Unable to set attribute information: " + e.toString ());
            }
        }
    }
}

Other Commons Attributes examples (source code examples)

Here is a short list of links related to this Commons Attributes RuntimeSample.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.