File: MockEnhancer.java

package info (click to toggle)
libjdo-api-java 3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,540 kB
  • ctags: 33,888
  • sloc: java: 120,520; sql: 20,353; xml: 3,969; makefile: 4
file content (136 lines) | stat: -rw-r--r-- 4,348 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 javax.jdo;


import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import static javax.jdo.Constants.PROPERTY_ENHANCER_VENDOR_NAME;
import static javax.jdo.Constants.PROPERTY_ENHANCER_VERSION_NUMBER;

import javax.jdo.metadata.JDOMetadata;


/**
 * Tests class javax.jdo.Enhancer (main class).
 * <p>
 */
public class MockEnhancer implements JDOEnhancer {

    static Properties props = new Properties();
    static {
        props.put(PROPERTY_ENHANCER_VENDOR_NAME, "Mock Enhancer");
        props.put(PROPERTY_ENHANCER_VERSION_NUMBER, "2.3.0");
        props.put("MockKey", "MockValue");
    }
    @SuppressWarnings("unused")
    private boolean verbose;
    private int numberOfElements;
    private List<String> classNames = new ArrayList<String>();
    private List<String> jarNames = new ArrayList<String>();
    private List<String> jdoNames = new ArrayList<String>();
    private List<String> puNames = new ArrayList<String>();
    @SuppressWarnings("unused")
    private String outputDirectory = null;

    public MockEnhancer(){
    }

    public Properties getProperties() {
        return props;
    }

    public JDOEnhancer setVerbose(boolean flag) {
        this.verbose = flag;
        return this;
    }

    public JDOEnhancer setOutputDirectory(String dirName) {
        outputDirectory = dirName;
        return this;
    }

    public JDOEnhancer setClassLoader(ClassLoader loader) {
        // check to see if JDOHelper is loadable from the loader
        try {
        loader.loadClass("javax.jdo.JDOHelper");
        } catch (ClassNotFoundException ex) {
            // bad
            throw new JDOFatalInternalException("Should be able to load JDOHelper from the class loader");
        }
        return this;
    }

    public JDOEnhancer addPersistenceUnit(String persistenceUnit) {
        numberOfElements++;
        this.puNames.add(persistenceUnit);
        return this;
    }

    public JDOEnhancer addClass(String className, byte[] bytes) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public JDOEnhancer addClasses(String... classNames) {
        numberOfElements += classNames.length;
        this.classNames.addAll(Arrays.asList(classNames));
        return this;
    }

    public JDOEnhancer addFiles(String... metadataFiles) {
        numberOfElements += metadataFiles.length;
        this.jdoNames.addAll(Arrays.asList(metadataFiles));
        return this;
    }

    public JDOEnhancer addJar(String jarFileName) {
        numberOfElements++;
        this.jarNames.add(jarFileName);
        return this;
    }

    public int enhance() {
        return numberOfElements;
    }

    public int validate() {
        return numberOfElements;
    }

    public byte[] getEnhancedBytes(String className) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void registerMetadata(JDOMetadata metadata) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public JDOMetadata newMetadata() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}