View Javadoc
1   /**
2    * Copyright 2014-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.jute.system;
17  
18  import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_NAME;
19  import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VENDOR;
20  import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
21  import static com.google.common.base.StandardSystemProperty.JAVA_VM_SPECIFICATION_NAME;
22  import static com.google.common.base.StandardSystemProperty.JAVA_VM_SPECIFICATION_VENDOR;
23  import static com.google.common.base.StandardSystemProperty.JAVA_VM_SPECIFICATION_VERSION;
24  import static org.kuali.common.jute.reflect.Reflection.checkNoNulls;
25  
26  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
27  
28  @JsonDeserialize(builder = Specification.Builder.class)
29  public final class Specification {
30  
31      private final String name;
32      private final String version;
33      private final String vendor;
34  
35      private Specification(Builder builder) {
36          this.name = builder.name;
37          this.version = builder.version;
38          this.vendor = builder.vendor;
39      }
40  
41      public static Specification buildRuntimeEnvironmentSpecification() {
42          Builder builder = builder();
43          builder.withVendor(JAVA_SPECIFICATION_VENDOR.value());
44          builder.withVersion(JAVA_SPECIFICATION_VERSION.value());
45          builder.withName(JAVA_SPECIFICATION_NAME.value());
46          return builder.build();
47      }
48  
49      public static Specification buildVirtualMachineSpecification() {
50          Builder builder = builder();
51          builder.withVendor(JAVA_VM_SPECIFICATION_VENDOR.value());
52          builder.withVersion(JAVA_VM_SPECIFICATION_VERSION.value());
53          builder.withName(JAVA_VM_SPECIFICATION_NAME.value());
54          return builder.build();
55      }
56  
57      public static Builder builder() {
58          return new Builder();
59      }
60  
61      public static class Builder implements org.apache.commons.lang3.builder.Builder<Specification> {
62  
63          private String name;
64          private String version;
65          private String vendor;
66  
67          public Builder withVendor(String vendor) {
68              this.vendor = vendor;
69              return this;
70          }
71  
72          public Builder withVersion(String version) {
73              this.version = version;
74              return this;
75          }
76  
77          public Builder withName(String name) {
78              this.name = name;
79              return this;
80          }
81  
82          @Override
83          public Specification build() {
84              return checkNoNulls(new Specification(this));
85          }
86      }
87  
88      public String getVendor() {
89          return vendor;
90      }
91  
92      public String getVersion() {
93          return version;
94      }
95  
96      public String getName() {
97          return name;
98      }
99  
100 }