ruby_stix 0.0.2-java → 0.2.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 112ae61c03f537dfd3b01d0dffaeedd15ad82300
4
- data.tar.gz: 695c4969f7eca8b727d458c77ae76597a8335782
3
+ metadata.gz: 6654f92dd53901b9543d13ea76cbc817e642ef41
4
+ data.tar.gz: 22144630e430838ed923a737a365a2a64cf75ee5
5
5
  SHA512:
6
- metadata.gz: c1ad8b82de21c3ddc359aaf98d7b0ead9f06dbe34b795efd2934c4730b4d741d4c72cf7d7e4279503aa9594b2b21d4d4af1ba6a807c27bffb3d3fc0bfd31777a
7
- data.tar.gz: 6a7731bf85bdd57817956d43c1c7e667643114fa245d39a6d6eb20e76670568ba7046d43fde478fa3875889d6e2e98c1c7f860931129167468ddb0689b1de1c2
6
+ metadata.gz: bf295cc3ae32825aef7755178ddaa50d02c45bf25484f61d608b2c468317182901dc6afdd5c397815efed951b18683b4f5dc5c21173a9447c6ad1f134b611f71
7
+ data.tar.gz: a3d506757be957d80dbed091121070537de11ade667ebd13d26ff91ded751e3e467576981f011b7a1b04613e0f403845dca3c049b3a7095957c7e44344a34738
Binary file
@@ -74,7 +74,8 @@ module StixRuby
74
74
  end
75
75
 
76
76
  IRREGULARS = {
77
- Regexp.new("tt_ps") => "ttps"
77
+ Regexp.new("tt_ps") => "ttps",
78
+ Regexp.new("co_as") => "coas"
78
79
  }
79
80
 
80
81
  NAMESPACE_MAPPINGS = {
@@ -6,12 +6,16 @@ java_import 'javax.xml.datatype.DatatypeFactory'
6
6
  ActiveSupport::Inflector.inflections do |inflect|
7
7
  inflect.acronym 'TTP'
8
8
  inflect.acronym 'TTPs'
9
+ inflect.acronym 'COA'
10
+ inflect.acronym 'COAs'
9
11
  end
10
12
 
11
13
  class Java::OrgMitre::ApiHelper
12
14
 
13
15
  BLACKLIST = ["getClass", "hashCode", "equals", "toString", "notify", "notifyAll", "wait"]
14
-
16
+
17
+ include StixRuby::Marshall
18
+
15
19
  def initialize(*args)
16
20
  # Every time we create an object, we try to annotate that object's class. If the class has been annotated already,
17
21
  # this does nothing.
@@ -69,7 +73,7 @@ class Java::OrgMitre::ApiHelper
69
73
 
70
74
  # If key/value pairs were passed, use them
71
75
  process_args(args).each do |key, value|
72
- process_single_argument(key, value)
76
+ process_single_argument(key, value) unless key == '@@class'
73
77
  end
74
78
  end
75
79
 
@@ -80,7 +84,6 @@ class Java::OrgMitre::ApiHelper
80
84
  # If we respond to the Ruby setter, call it. This allows Ruby-style keyword argument names to be used
81
85
  elsif self.respond_to?("#{k}=")
82
86
  self.send("#{k}=", v)
83
- # If the value is an array, we can handle it a little differently
84
87
  # Note that some array arguments might get caught by the setter
85
88
  elsif v.kind_of?(Array)
86
89
  # Find the Java method name even if we used a Ruby-style name. This is imperfect so may throw errors.
@@ -107,6 +110,10 @@ class Java::OrgMitre::ApiHelper
107
110
  "get#{k}"
108
111
  elsif self.respond_to?("get#{to_java_name(k)}")
109
112
  "get#{to_java_name(k)}"
113
+ elsif k == 'ttps'
114
+ "getTTPS"
115
+ elsif k == 'coas'
116
+ "getCOAS"
110
117
  else
111
118
  raise "Unable to find corresponding java method for #{k}"
112
119
  end
@@ -115,7 +122,7 @@ class Java::OrgMitre::ApiHelper
115
122
  # Finds the expected class for a list by parsing it out of the Java signature. This kind of blows but the way Java
116
123
  # implements generics (type erasure) means the JRuby code does not have access to the generic type.
117
124
  def find_generic_argument_for(k)
118
- return eval(self.java_class.java_method(k).to_generic_string.match(/<(.+)>/)[1])
125
+ Java::JavaClass.for_name(self.java_class.java_method(k).to_generic_string.match(/<(.+)>/)[1]).ruby_class
119
126
  end
120
127
 
121
128
  # Convert a Ruby-style method name (lower snake) to a Java-style method name (camel)
@@ -126,7 +133,7 @@ class Java::OrgMitre::ApiHelper
126
133
 
127
134
  # Generate a random ID. Uses the ID namespace if it's been set.
128
135
  def generate_id!
129
- self.id = StixRuby.generate_id(self.class.to_s.split('::').last.gsub('Type', '').downcase)
136
+ self.id = StixRuby.generate_id(self.class.name.split('::').last.gsub('Type', '').downcase)
130
137
  end
131
138
 
132
139
  # Theoretically method_missing might be used for more, but currently it just tries to catch "add_"
@@ -149,7 +156,7 @@ class Java::OrgMitre::ApiHelper
149
156
  # We already have an item in the list, so just add the new one
150
157
  intermediate = send(java_method_name)
151
158
  argument_type = intermediate.find_generic_argument_for(java_method_name)
152
- intermediate.send(java_method_name).add(auto_create_object(argument_type, args.first))
159
+ intermediate.send(java_method_name).add(auto_create_object(argument_type, args.first))
153
160
  end
154
161
  else
155
162
  super
@@ -157,6 +164,8 @@ class Java::OrgMitre::ApiHelper
157
164
  else
158
165
  super
159
166
  end
167
+ elsif respond_to?("is_#{method_name}")
168
+ send("is_#{method_name}")
160
169
  else
161
170
  super
162
171
  end
@@ -179,6 +188,7 @@ class Java::OrgMitre::ApiHelper
179
188
  end
180
189
 
181
190
  def self.annotate!
191
+ return if @annotated == true
182
192
  # Mark us as annotated
183
193
  @annotated = true
184
194
 
@@ -197,7 +207,7 @@ class Java::OrgMitre::ApiHelper
197
207
  # to handle arrays appropriately and call constructors automatically when necessary
198
208
  self.setter_methods.each do |method_name, java_method|
199
209
  # Find the type of the argument and the name of the method
200
- argument_type = java_method.argument_types.first.ruby_class
210
+ argument_type = java_method.argument_types.first.ruby_class
201
211
 
202
212
  # Do not annotate this method if it's already annotated or has a basic value constructor
203
213
  next if argument_type == Java::JavaLang::Object || self.annotated_method?(method_name)
@@ -227,7 +237,7 @@ class Java::OrgMitre::ApiHelper
227
237
  object = auto_create_object(argument_type, args.first)
228
238
 
229
239
  send(method_name + "Raw", object)
230
- end
240
+ end
231
241
  end
232
242
  end
233
243
  end
@@ -263,16 +273,27 @@ class Java::OrgMitre::ApiHelper
263
273
  end
264
274
 
265
275
  def auto_create_object(argument_type, arg)
266
- if arg.kind_of?(argument_type)
276
+ subclass = arg.kind_of?(Hash) && arg.delete('@@class')
277
+
278
+ if arg.nil?
279
+ nil
280
+ elsif arg.kind_of?(argument_type)
267
281
  arg
268
- elsif argument_type.respond_to?(:from_value)
269
- argument_type.from_value(arg)
282
+ elsif argument_type.respond_to?(:from_value) && (arg.kind_of?(String) || arg.keys == ['@@class', 'value'])
283
+ argument_type.from_value(arg.kind_of?(String) ? arg : arg['value'])
270
284
  # Handle an array argument
271
285
  # JAXB dates are really F'd up, so autoconvert them
272
286
  elsif argument_type == javax.xml.datatype.XMLGregorianCalendar
273
287
  calendar = java.util.GregorianCalendar.new
274
- calendar.setTime(arg.to_java)
275
- DatatypeFactory.newInstance.newXMLGregorianCalendar(calendar)
288
+ if arg.kind_of?(String)
289
+ arg = Time.parse(arg)
290
+ calendar.setTime(arg.to_java)
291
+ DatatypeFactory.newInstance.newXMLGregorianCalendar(calendar)
292
+ else
293
+ nil
294
+ end
295
+ elsif subclass
296
+ subclass.constantize.new(arg)
276
297
  else
277
298
  argument_type.new(arg)
278
299
  end
@@ -304,4 +325,4 @@ class Java::OrgMitre::ApiHelper
304
325
  def annotate_class!
305
326
  self.class.annotate! unless annotated?
306
327
  end
307
- end
328
+ end
@@ -1,6 +1,4 @@
1
1
  class Java::OrgMitreStixCore::STIXType
2
- include StixRuby::Marshall
3
-
4
2
  def add_observable(observable)
5
3
  self.observables ||= org.mitre.cybox.core.ObservablesType.new(:cybox_major_version => '2', :cybox_minor_version => '1')
6
4
  self.observables.add_observable(observable)
@@ -50,7 +48,7 @@ class Java::OrgMitreStixCore::STIXType
50
48
  end
51
49
 
52
50
  def process_args(args)
53
- args[:version] ||= "1.0.1"
51
+ args[:version] ||= "1.1.1"
54
52
  args
55
53
  end
56
54
  end
@@ -1,3 +1,3 @@
1
1
  module StixRuby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.2.0"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_stix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - John Wunder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-24 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri