Merge "Add site definition in distributionManagement"
[ccsdk/sli/core.git] / sli / common / src / main / java / org / onap / ccsdk / sli / core / sli / PrintYangToProp.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.core.sli;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.PrintStream;
29 import java.io.FileDescriptor;
30 import java.lang.reflect.Constructor;
31 import java.lang.reflect.InvocationTargetException;
32 import java.lang.reflect.Method;
33 import java.lang.reflect.Modifier;
34 import java.lang.reflect.ParameterizedType;
35 import java.lang.reflect.Type;
36 import java.util.LinkedList;
37 import java.util.List;
38 import java.util.Properties;
39 import java.util.Arrays;
40 import java.util.ArrayList;
41 import java.io.*;
42 import org.opendaylight.yangtools.yang.binding.Identifier;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
51
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54
55 import com.google.common.base.CaseFormat;
56
57 public class PrintYangToProp {
58
59         private static final Logger LOG = LoggerFactory.getLogger(PrintYangToProp.class);
60         public static final String PROPERTIES_FILE="";
61         private static Properties properties;
62         
63         public static Properties prop = new Properties();
64         public static ArrayList<String> propList = new ArrayList<String>();
65
66         
67         public static Properties toProperties(Properties props, Object fromObj) {
68                 Class fromClass = null;
69                 
70                 if (fromObj != null)
71                 {
72                         fromClass = fromObj.getClass();
73                 }
74                 return (toProperties(props, "", fromObj, fromClass));
75         }
76         
77         public static Properties toProperties(Properties props, String pfx, Object fromObj)
78         {
79                 Class fromClass = null;
80                 
81                 if (fromObj != null)
82                 {
83                         fromClass = fromObj.getClass();
84                 }
85                 
86                 return(toProperties(props, pfx, fromObj, fromClass));
87         }
88
89         public static Properties toProperties(Properties props, String pfx,
90                         Object fromObj, Class fromClass) {
91
92                 if (fromObj == null) {
93                         return (props);
94                 }
95         
96                 
97                 String simpleName = fromClass.getSimpleName();
98
99                 //LOG.debug("Extracting properties from " + fromClass.getName()
100                 //              + " class");
101                 if (fromObj instanceof List) {
102
103                         // Class is a List. List should contain yang-generated classes.
104                         //LOG.debug(fromClass.getName() + " is a List");
105
106                         List fromList = (List) fromObj;
107
108                         for (int i = 0; i < fromList.size(); i++) {
109                                 toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass);
110                         }
111                         props.setProperty(pfx + "_length", "" + fromList.size());
112
113                 } else if (isYangGenerated(fromClass)) {
114                         // Class is yang generated.
115                         //LOG.debug(fromClass.getName() + " is a Yang-generated class");
116
117                         String propNamePfx = null;
118
119                         // If called from a list (so prefix ends in ']'), don't
120                         // add class name again
121                         if (pfx.endsWith("]")) {
122                                 propNamePfx = pfx;
123                         } else {
124                                 if ((pfx != null) && (pfx.length() > 0)) {
125                                         propNamePfx = pfx ;
126                                 } else {
127                                         propNamePfx = toLowerHyphen(fromClass.getSimpleName());
128                                 }
129
130                                 if (propNamePfx.endsWith("-builder")) {
131                                         propNamePfx = propNamePfx.substring(0, propNamePfx.length()
132                                                         - "-builder".length());
133                                 }
134
135                                 if (propNamePfx.endsWith("-impl")) {
136                                         propNamePfx = propNamePfx.substring(0, propNamePfx.length()
137                                                         - "-impl".length());
138                                 }
139                         }
140                         
141                         // Iterate through getter methods to figure out values we need to
142                         // save from
143
144                         for (Method m : fromClass.getMethods()) {
145                                 // LOG.debug("Checking " + m.getName() + " method");
146                                 if (isGetter(m)) {
147                                         // LOG.debug(m.getName() + " is a getter");
148                                         Class returnType = m.getReturnType();
149                                         String fieldName = toLowerHyphen(m.getName().substring(3));
150                                         if(m != null && m.getName().matches("^is[A-Z].*")){
151                                                 fieldName = toLowerHyphen(m.getName().substring(2));
152                                         }
153
154                                         fieldName = fieldName.substring(0, 1).toLowerCase()
155                                                         + fieldName.substring(1);
156
157                                         // Is the return type a yang generated class?
158                                         if (isYangGenerated(returnType)) {
159                                                 //System.out.println("returnType:"  +returnType);
160                                                 // Is it an enum?
161                                                 if (returnType.isEnum()) {
162                                                         // Return type is a typedef. Save its value.
163                                                         try {
164                                                                 boolean isAccessible = m.isAccessible();
165                                                                 if (!isAccessible) {
166                                                                         m.setAccessible(true);
167                                                                 }
168
169                                                                 Object retValue = m.invoke(fromObj);
170
171                                                                 if (!isAccessible) {
172                                                                         m.setAccessible(isAccessible);
173                                                                 }
174                                                                 if (retValue != null) {
175                                                                         String propName = propNamePfx + "."
176                                                                                         + fieldName;
177                                                                         String propVal = retValue.toString();
178                                                                         String yangProp = "yang." + fieldName + "." + propVal;
179                                                                         if ( properties.containsKey(yangProp)) {
180                                                                                 propVal = properties.getProperty(yangProp);
181                                                                                 //LOG.debug("Adjusting property " + yangProp + " " + propVal);
182                                                                         }
183                                                                         //LOG.debug("Setting property " + propName
184                                                                         //              + " to " + propVal);
185                                                                         props.setProperty(propName, propVal);
186                                                                 }
187                                                         } catch (Exception e) {
188                                                                 LOG.error(
189                                                                                 "Caught exception trying to convert Yang-generated enum returned by "
190                                                                                                 + fromClass.getName() + "."
191                                                                                                 + m.getName()
192                                                                                                 + "() to Properties entry", e);
193                                                         }
194                                                 } else if (isIpv4Address(returnType)) {
195                                                         // Save its value
196                                                         try {
197                                                                 String propName = propNamePfx + "." + fieldName;
198                                                                 boolean isAccessible = m.isAccessible();
199                                                                 if (!isAccessible) {
200                                                                         m.setAccessible(true);
201                                                                 }
202                                                                 Ipv4Address retValue = (Ipv4Address) m.invoke(fromObj);
203                                                                 if (!isAccessible) {
204                                                                         m.setAccessible(isAccessible);
205                                                                 }
206
207                                                                 if (retValue != null) {
208                                                                         String propVal = retValue.getValue().toString();
209                                                                         //LOG.debug("Setting property " + propName
210                                                                         //              + " to " + propVal);
211                                                                         props.setProperty(propName, propVal);
212
213                                                                 }
214                                                         } catch (Exception e) {
215                                                                 LOG.error(
216                                                                                 "Caught exception trying to convert value returned by "
217                                                                                                 + fromClass.getName() + "."
218                                                                                                 + m.getName()
219                                                                                                 + "() to Properties entry", e);
220                                                         }
221                                                 } else if (isIpv6Address(returnType)) {
222                                                         // Save its value
223                                                         try {
224                                                                 String propName = propNamePfx + "." + fieldName;
225                                                                 boolean isAccessible = m.isAccessible();
226                                                                 if (!isAccessible) {
227                                                                         m.setAccessible(true);
228                                                                 }
229                                                                 Ipv6Address retValue = (Ipv6Address) m.invoke(fromObj);
230                                                                 if (!isAccessible) {
231                                                                         m.setAccessible(isAccessible);
232                                                                 }
233
234                                                                 if (retValue != null) {
235                                                                         String propVal = retValue.getValue().toString();
236                                                                         //LOG.debug("Setting property " + propName
237                                                                         //              + " to " + propVal);
238                                                                         props.setProperty(propName, propVal);
239
240                                                                 }
241                                                         } catch (Exception e) {
242                                                                 LOG.error(
243                                                                                 "Caught exception trying to convert value returned by "
244                                                                                                 + fromClass.getName() + "."
245                                                                                                 + m.getName()
246                                                                                                 + "() to Properties entry", e);
247                                                         }
248                                                 } else if (isIpv4Prefix(returnType)) {
249                                                         //System.out.println("isIpv4Prefix");
250                                                         // Save its value
251                                                         try {
252                                                                 String propName = propNamePfx + "." + fieldName;
253                                                                 boolean isAccessible = m.isAccessible();
254                                                                 if (!isAccessible) {
255                                                                         m.setAccessible(true);
256                                                                 }
257                                                                 Ipv4Prefix retValue = (Ipv4Prefix) m.invoke(fromObj);
258                                                                 if (!isAccessible) {
259                                                                         m.setAccessible(isAccessible);
260                                                                 }
261
262                                                                 if (retValue != null) {
263                                                                         String propVal = retValue.getValue().toString();
264                                                                         //LOG.debug("Setting property " + propName
265                                                                         //              + " to " + propVal);
266                                                                         props.setProperty(propName, propVal);
267
268                                                                 }
269                                                         } catch (Exception e) {
270                                                                 LOG.error(
271                                                                                 "Caught exception trying to convert value returned by "
272                                                                                                 + fromClass.getName() + "."
273                                                                                                 + m.getName()
274                                                                                                 + "() to Properties entry", e);
275                                                         }
276                                                 } else if (isIpv6Prefix(returnType)) {
277                                                         //System.out.println("isIpv6Prefix");
278                                                         // Save its value
279                                                         try {
280                                                                 String propName = propNamePfx + "." + fieldName;
281                                                                 boolean isAccessible = m.isAccessible();
282                                                                 if (!isAccessible) {
283                                                                         m.setAccessible(true);
284                                                                 }
285                                                                 Ipv6Prefix retValue = (Ipv6Prefix) m.invoke(fromObj);
286                                                                 if (!isAccessible) {
287                                                                         m.setAccessible(isAccessible);
288                                                                 }
289
290                                                                 if (retValue != null) {
291                                                                         String propVal = retValue.getValue().toString();
292                                                                         //LOG.debug("Setting property " + propName
293                                                                         //              + " to " + propVal);
294                                                                         props.setProperty(propName, propVal);
295
296                                                                 }
297                                                         } catch (Exception e) {
298                                                                 LOG.error(
299                                                                                 "Caught exception trying to convert value returned by "
300                                                                                                 + fromClass.getName() + "."
301                                                                                                 + m.getName()
302                                                                                                 + "() to Properties entry", e);
303                                                         }
304                                                 } else {
305                                                         try {
306                                                                 boolean isAccessible = m.isAccessible();
307                                                                 if (!isAccessible) {
308                                                                         m.setAccessible(true);
309                                                                 }
310                                                                 Object retValue = m.invoke(fromObj);
311                                                                 if (!isAccessible) {
312                                                                         m.setAccessible(isAccessible);
313                                                                 }
314                                                                 if (retValue != null) {
315                                                                         toProperties(props, propNamePfx + "." + fieldName, retValue, returnType);
316                                                                 }
317                                                         } catch (Exception e) {
318                                                                 LOG.error(
319                                                                                 "Caught exception trying to convert Yang-generated class returned by"
320                                                                                                 + fromClass.getName() + "."
321                                                                                                 + m.getName()
322                                                                                                 + "() to Properties entry", e);
323                                                         }
324                                                 }
325                                         } else if (returnType.equals(Class.class)) {
326
327                                                 //LOG.debug(m.getName()
328                                                 //              + " returns a Class object - not interested");
329
330                                         } else if (List.class.isAssignableFrom(returnType)) {
331
332                                                 // This getter method returns a list.
333                                                 try {
334                                                         boolean isAccessible = m.isAccessible();
335                                                         if (!isAccessible) {
336                                                                 m.setAccessible(true);
337                                                         }
338                                                         Object retList = m.invoke(fromObj);
339                                                         if (!isAccessible) {
340                                                                 m.setAccessible(isAccessible);
341                                                         }
342                                                         // Figure out what type of elements are stored in this array.
343                                                         Type paramType = m.getGenericReturnType();
344                                                         Type elementType = ((ParameterizedType) paramType)
345                                                                         .getActualTypeArguments()[0];
346                                                         toProperties(props, propNamePfx + "." + fieldName,
347                                                                         retList, (Class)elementType);
348                                                 } catch (Exception e) {
349                                                         LOG.error(
350                                                                         "Caught exception trying to convert List returned by "
351                                                                                         + fromClass.getName() + "."
352                                                                                         + m.getName()
353                                                                                         + "() to Properties entry", e);
354                                                 }
355
356                                         } else {
357
358                                                 // Method returns something that is not a List and not
359                                                 // yang-generated.
360                                                 // Save its value
361                                                 try {
362                                                         String propName = propNamePfx + "." + fieldName;
363                                                         boolean isAccessible = m.isAccessible();
364                                                         if (!isAccessible) {
365                                                                 m.setAccessible(true);
366                                                         }
367                                                         Object propValObj = m.invoke(fromObj);
368                                                         if (!isAccessible) {
369                                                                 m.setAccessible(isAccessible);
370                                                         }
371
372                                                         if (propValObj != null) {
373                                                                 String propVal = propValObj.toString();
374                                                                 //LOG.debug("Setting property " + propName
375                                                                 //              + " to " + propVal);
376                                                                 props.setProperty(propName, propVal);
377
378                                                         }
379                                                 } catch (Exception e) {
380                                                         LOG.error(
381                                                                         "Caught exception trying to convert value returned by "
382                                                                                         + fromClass.getName() + "."
383                                                                                         + m.getName()
384                                                                                         + "() to Properties entry", e);
385                                                 }
386                                         }
387
388                                 }
389                         }
390
391                 } else {
392                         // Class is not yang generated and not a list
393                         // Do nothing.
394
395                 }
396
397                 return (props);
398         }
399
400         public static Object toBuilder(Properties props, Object toObj) {
401
402                 return (toBuilder(props, "", toObj));
403         }
404
405         public static List toList(Properties props, String pfx, List toObj,
406                         Class elemType) {
407
408                 int maxIdx = -1;
409                 boolean foundValue = false;
410
411                 //LOG.debug("Saving properties to List<" + elemType.getName()
412                 //              + ">  from " + pfx);
413
414                 // Figure out array size
415                 for (Object pNameObj : props.keySet()) {
416                         String key = (String) pNameObj;
417
418                         if (key.startsWith(pfx + "[")) {
419                                 String idxStr = key.substring(pfx.length() + 1);
420                                 int endloc = idxStr.indexOf("]");
421                                 if (endloc != -1) {
422                                         idxStr = idxStr.substring(0, endloc);
423                                 }
424
425                                 try {
426                                         int curIdx = Integer.parseInt(idxStr);
427                                         if (curIdx > maxIdx) {
428                                                 maxIdx = curIdx;
429                                         }
430                                 } catch (Exception e) {
431                                         LOG.error("Illegal subscript in property " + key);
432                                 }
433
434                         }
435                 }
436
437                 //LOG.debug(pfx + " has max index of " + maxIdx);
438                 for (int i = 0; i <= maxIdx; i++) {
439
440                         String curBase = pfx + "[" + i + "]";
441
442                         if (isYangGenerated(elemType)) {
443                                 String builderName = elemType.getName() + "Builder";
444                                 try {
445                                         Class builderClass = Class.forName(builderName);
446                                         Object builderObj = builderClass.newInstance();
447                                         Method buildMethod = builderClass.getMethod("build");
448                                         builderObj = toBuilder(props, curBase, builderObj, true);
449                                         if (builderObj != null) {
450                                                 //LOG.debug("Calling " + builderObj.getClass().getName()
451                                                 //              + "." + buildMethod.getName() + "()");
452                                                 Object builtObj = buildMethod.invoke(builderObj);
453                                                 toObj.add(builtObj);
454                                                 foundValue = true;
455                                         }
456
457                                 } catch (ClassNotFoundException e) {
458                                         LOG.warn("Could not find builder class " + builderName, e);
459                                 } catch (Exception e) {
460                                         LOG.error("Caught exception trying to populate list from "
461                                                         + pfx);
462                                 }
463                         }
464
465                 }
466
467                 if (foundValue) {
468                         return (toObj);
469                 } else {
470                         return (null);
471                 }
472
473         }
474         
475         public static Object toBuilder(Properties props, String pfx, Object toObj) {
476                 return(toBuilder(props, pfx, toObj, false));
477         }
478
479         public static Object toBuilder(Properties props, String pfx, Object toObj, boolean preservePfx) {
480                 Class toClass = toObj.getClass();
481                 boolean foundValue = false;
482
483                 //LOG.debug("Saving properties to " + toClass.getName() + " class from "
484                 //              + pfx);
485
486                 Ipv4Address addr;
487
488                 if (isYangGenerated(toClass)) {
489                         // Class is yang generated.
490                         //LOG.debug(toClass.getName() + " is a Yang-generated class");
491
492                         String propNamePfx = null;
493                         if (preservePfx) {
494                                 propNamePfx = pfx;
495                         } else {
496
497                                 if ((pfx != null) && (pfx.length() > 0)) {
498                                         propNamePfx = pfx + "."
499                                                         + toLowerHyphen(toClass.getSimpleName());
500                                 } else {
501                                         propNamePfx = toLowerHyphen(toClass.getSimpleName());
502                                 }
503
504                                 if (propNamePfx.endsWith("-builder")) {
505                                         propNamePfx = propNamePfx.substring(0, propNamePfx.length()
506                                                         - "-builder".length());
507                                 }
508
509                                 if (propNamePfx.endsWith("-impl")) {
510                                         propNamePfx = propNamePfx.substring(0, propNamePfx.length()
511                                                         - "-impl".length());
512                                 }
513                         }
514
515                         if (toObj instanceof Identifier) {
516                                 //LOG.debug(toClass.getName() + " is a Key - skipping");
517                                 return (toObj);
518                         }
519
520                         // Iterate through getter methods to figure out values we need to
521                         // set
522
523                         for (Method m : toClass.getMethods()) {
524                                 // LOG.debug("Is " + m.getName() + " method a setter?");
525                                 if (isSetter(m)) {
526                                         // LOG.debug(m.getName() + " is a setter");
527                                         Class paramTypes[] = m.getParameterTypes();
528                                         Class paramClass = paramTypes[0];
529
530                                         String fieldName = toLowerHyphen(m.getName().substring(3));
531                                         fieldName = fieldName.substring(0, 1).toLowerCase()
532                                                         + fieldName.substring(1);
533
534                                         String propName = propNamePfx + "." + fieldName;
535
536                                         String paramValue = props.getProperty(propName);
537                                         if (paramValue == null) {
538                                                 //LOG.debug(propName + " is unset");
539                                         } else {
540                                                 //LOG.debug(propName + " = " + paramValue);
541                                         }
542
543                                         // Is the return type a yang generated class?
544                                         if (isYangGenerated(paramClass)) {
545                                                 // Is it an enum?
546                                                 if (paramClass.isEnum()) {
547
548                                                         //LOG.debug(m.getName() + " expects an Enum");
549                                                         // Param type is a typedef.
550                                                         if (paramValue != null) {
551                                                                 Object paramObj = null;
552
553                                                                 try {
554                                                                         paramObj = Enum.valueOf(paramClass,
555                                                                                         toUpperCamelCase(paramValue));
556                                                                 } catch (Exception e) {
557                                                                         LOG.error(
558                                                                                         "Caught exception trying to convert field "
559                                                                                                         + propName + " to enum "
560                                                                                                         + paramClass.getName(), e);
561                                                                 }
562
563                                                                 try {
564                                                                         boolean isAccessible = m.isAccessible();
565                                                                         if (!isAccessible) {
566                                                                                 m.setAccessible(true);
567                                                                         }
568
569                                                                         //LOG.debug("Calling "
570                                                                         //              + toObj.getClass().getName() + "."
571                                                                         //              + m.getName() + "(" + paramValue
572                                                                         //              + ")");
573                                                                         m.invoke(toObj, paramObj);
574
575                                                                         if (!isAccessible) {
576                                                                                 m.setAccessible(isAccessible);
577                                                                         }
578                                                                         foundValue = true;
579
580                                                                 } catch (Exception e) {
581                                                                         LOG.error(
582                                                                                         "Caught exception trying to create Yang-generated enum expected by"
583                                                                                                         + toClass.getName()
584                                                                                                         + "."
585                                                                                                         + m.getName()
586                                                                                                         + "() from Properties entry",
587                                                                                         e);
588                                                                 }
589                                                         }
590                                                 } else {
591
592                                                         String simpleName = paramClass.getSimpleName();
593                                                 LOG.info("simpleName:" + simpleName);
594
595                                                         if ("Ipv4Address".equals(simpleName)
596                                                                         || "Ipv6Address".equals(simpleName) || "Ipv4Prefix".equals(simpleName) || "Ipv6Prefix".equals(simpleName)) {
597                                                         
598                                                                 if (paramValue != null) {
599                                                         if("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName)){
600                                                                         try {
601                                                                                 IpAddress ipAddr = IpAddressBuilder
602                                                                                                 .getDefaultInstance(paramValue);
603
604
605                                                                                 if ("Ipv4Address".equals(simpleName))
606                                                                                 {
607                                                                                         m.invoke(toObj, ipAddr.getIpv4Address());
608                                                                                 }
609                                                                                 else
610                                                                                 {
611                                                                                         m.invoke(toObj, ipAddr.getIpv6Address());
612
613                                                                                 }
614                                                                                 foundValue = true;
615                                                                         } catch (Exception e) {
616                                                                                 LOG.error(
617                                                                                                 "Caught exception calling "
618                                                                                                                 + toClass.getName() + "."
619                                                                                                                 + m.getName() + "("
620                                                                                                                 + paramValue + ")", e);
621
622                                                                         }
623                                                         }else if("Ipv4Prefix".equals(simpleName)|| "Ipv6Prefix".equals(simpleName)){
624                                                                         try {
625                                                                                 IpPrefix ipPrefix = IpPrefixBuilder
626                                                                                                 .getDefaultInstance(paramValue);
627
628
629                                                                                 if ("Ipv4Prefix".equals(simpleName))
630                                                                                 {
631                                                                                         m.invoke(toObj, ipPrefix.getIpv4Prefix());
632                                                                                 }
633                                                                                 else
634                                                                                 {
635                                                                                         m.invoke(toObj, ipPrefix.getIpv6Prefix());
636
637                                                                                 }
638                                                                                 foundValue = true;
639                                                                         } catch (Exception e) {
640                                                                                 LOG.error(
641                                                                                                 "Caught exception calling "
642                                                                                                                 + toClass.getName() + "."
643                                                                                                                 + m.getName() + "("
644                                                                                                                 + paramValue + ")", e);
645
646                                                                 }
647                                                         }
648                                                         }
649
650                                                         } else {
651                                                                 // setter expects a yang-generated class. Need
652                                                                 // to
653                                                                 // create a builder to set it.
654
655                                                                 String builderName = paramClass.getName()
656                                                                                 + "Builder";
657                                                                 Class builderClass = null;
658                                                                 Object builderObj = null;
659                                                                 Object paramObj = null;
660
661                                                                 //LOG.debug(m.getName()
662                                                                 //              + " expects a yang-generated class - looking for builder "
663                                                                 //              + builderName);
664                                                                 try {
665                                                                         builderClass = Class.forName(builderName);
666                                                                         builderObj = builderClass.newInstance();
667                                                                         paramObj = toBuilder(props, propNamePfx,
668                                                                                         builderObj);
669                                                                 } catch (ClassNotFoundException e) {
670                                                                         Object constObj = null;
671                                                                         try {
672                                                                                 // See if I can find a constructor I can
673                                                                                 // use
674                                                                                 Constructor[] constructors = paramClass
675                                                                                                 .getConstructors();
676                                                                                 // Is there a String constructor?
677                                                                                 for (Constructor c : constructors) {
678                                                                                         Class[] cParms = c
679                                                                                                         .getParameterTypes();
680                                                                                         if ((cParms != null)
681                                                                                                         && (cParms.length == 1)) {
682                                                                                                 if (String.class
683                                                                                                                 .isAssignableFrom(cParms[0])) {
684                                                                                                         constObj = c
685                                                                                                                         .newInstance(paramValue);
686                                                                                                 }
687                                                                                         }
688                                                                                 }
689
690                                                                                 if (constObj == null) {
691                                                                                         // Is there a Long constructor?
692                                                                                         for (Constructor c : constructors) {
693                                                                                                 Class[] cParms = c
694                                                                                                                 .getParameterTypes();
695                                                                                                 if ((cParms != null)
696                                                                                                                 && (cParms.length == 1)) {
697                                                                                                         if (Long.class
698                                                                                                                         .isAssignableFrom(cParms[0])) {
699                                                                                                                 constObj = c
700                                                                                                                                 .newInstance(Long
701                                                                                                                                                 .parseLong(paramValue));
702                                                                                                         }
703                                                                                                 }
704                                                                                         }
705
706                                                                                 }
707
708                                                                                 if (constObj != null) {
709                                                                                         try {
710                                                                                                 m.invoke(toObj, constObj);
711                                                                                                 foundValue = true;
712                                                                                         } catch (Exception e2) {
713                                                                                                 LOG.error(
714                                                                                                                 "Caught exception trying to call "
715                                                                                                                                 + m.getName(),
716                                                                                                                 e2);
717                                                                                         }
718                                                                                 }
719                                                                         } catch (Exception e1) {
720                                                                                 LOG.warn(
721                                                                                                 "Could not find a suitable constructor for "
722                                                                                                                 + paramClass.getName(),
723                                                                                                 e1);
724                                                                         }
725
726                                                                         if (paramObj == null) {
727                                                                                 LOG.warn("Could not find builder class "
728                                                                                                 + builderName
729                                                                                                 + " and could not find a String or Long constructor - trying just to set passing paramValue");
730
731                                                                         }
732
733                                                                 } catch (Exception e) {
734                                                                         LOG.error(
735                                                                                         "Caught exception trying to create builder "
736                                                                                                         + builderName, e);
737                                                                 }
738
739                                                                 if (paramObj != null) {
740
741                                                                         try {
742
743                                                                                 Method buildMethod = builderClass
744                                                                                                 .getMethod("build");
745                                                                                 //LOG.debug("Calling "
746                                                                                 //              + paramObj.getClass().getName()
747                                                                                 //              + "." + buildMethod.getName()
748                                                                                 //              + "()");
749                                                                                 Object builtObj = buildMethod
750                                                                                                 .invoke(paramObj);
751
752                                                                                 boolean isAccessible = m.isAccessible();
753                                                                                 if (!isAccessible) {
754                                                                                         m.setAccessible(true);
755                                                                                 }
756
757                                                                                 //LOG.debug("Calling "
758                                                                                 //              + toObj.getClass().getName()
759                                                                                 //              + "." + m.getName() + "()");
760                                                                                 m.invoke(toObj, builtObj);
761                                                                                 if (!isAccessible) {
762                                                                                         m.setAccessible(isAccessible);
763                                                                                 }
764                                                                                 foundValue = true;
765
766                                                                         } catch (Exception e) {
767                                                                                 LOG.error(
768                                                                                                 "Caught exception trying to set Yang-generated class expected by"
769                                                                                                                 + toClass.getName()
770                                                                                                                 + "."
771                                                                                                                 + m.getName()
772                                                                                                                 + "() from Properties entry",
773                                                                                                 e);
774                                                                         }
775                                                                 } else {
776                                                                         try {
777                                                                                 boolean isAccessible = m.isAccessible();
778                                                                                 if (!isAccessible) {
779                                                                                         m.setAccessible(true);
780                                                                                 }
781                                                                                 //LOG.debug("Calling "
782                                                                                 //              + toObj.getClass().getName()
783                                                                                 //              + "." + m.getName() + "("
784                                                                                 //              + paramValue + ")");
785                                                                                 m.invoke(toObj, paramValue);
786                                                                                 if (!isAccessible) {
787                                                                                         m.setAccessible(isAccessible);
788                                                                                 }
789                                                                                 foundValue = true;
790
791                                                                         } catch (Exception e) {
792                                                                                 LOG.error(
793                                                                                                 "Caught exception trying to convert value returned by"
794                                                                                                                 + toClass.getName()
795                                                                                                                 + "."
796                                                                                                                 + m.getName()
797                                                                                                                 + "() to Properties entry",
798                                                                                                 e);
799                                                                         }
800                                                                 }
801                                                         }
802                                                         }
803                                                 }else {
804
805                                                 // Setter's argument is not a yang-generated class. See
806                                                 // if it is a List.
807
808                                                 if (List.class.isAssignableFrom(paramClass)) {
809
810                                                         //LOG.debug("Parameter class " + paramClass.getName()
811                                                         //              + " is a List");
812
813                                                         // Figure out what type of args are in List and pass
814                                                         // that to toList().
815
816                                                         Type paramType = m.getGenericParameterTypes()[0];
817                                                         Type elementType = ((ParameterizedType) paramType)
818                                                                         .getActualTypeArguments()[0];
819                                                         Object paramObj = new LinkedList();
820                                                         try {
821                                                                 paramObj = toList(props, propName,
822                                                                                 (List) paramObj, (Class) elementType);
823                                                         } catch (Exception e) {
824                                                                 LOG.error("Caught exception trying to create list expected as argument to "
825                                                                                 + toClass.getName() + "." + m.getName());
826                                                         }
827
828                                                         if (paramObj != null) {
829                                                                 try {
830                                                                         boolean isAccessible = m.isAccessible();
831                                                                         if (!isAccessible) {
832                                                                                 m.setAccessible(true);
833                                                                         }
834                                                                         //LOG.debug("Calling "
835                                                                         //              + toObj.getClass().getName() + "."
836                                                                         //              + m.getName() + "(" + paramValue
837                                                                         //              + ")");
838                                                                         m.invoke(toObj, paramObj);
839                                                                         if (!isAccessible) {
840                                                                                 m.setAccessible(isAccessible);
841                                                                         }
842                                                                         foundValue = true;
843
844                                                                 } catch (Exception e) {
845                                                                         LOG.error(
846                                                                                         "Caught exception trying to convert List returned by"
847                                                                                                         + toClass.getName() + "."
848                                                                                                         + m.getName()
849                                                                                                         + "() to Properties entry",
850                                                                                         e);
851                                                                 }
852                                                         }
853                                                 } else {
854
855                                                         // Setter expects something that is not a List and
856                                                         // not yang-generated. Just pass the parameter value
857
858                                                         //LOG.debug("Parameter class "
859                                                         //              + paramClass.getName()
860                                                         //              + " is not a yang-generated class or a List");
861
862                                                         if (paramValue != null) {
863
864                                                                 Object constObj = null;
865
866                                                                 try {
867                                                                         // See if I can find a constructor I can use
868                                                                         Constructor[] constructors = paramClass
869                                                                                         .getConstructors();
870                                                                         // Is there a String constructor?
871                                                                         for (Constructor c : constructors) {
872                                                                                 Class[] cParms = c.getParameterTypes();
873                                                                                 if ((cParms != null)
874                                                                                                 && (cParms.length == 1)) {
875                                                                                         if (String.class
876                                                                                                         .isAssignableFrom(cParms[0])) {
877                                                                                                 constObj = c
878                                                                                                                 .newInstance(paramValue);
879                                                                                         }
880                                                                                 }
881                                                                         }
882
883                                                                         if (constObj == null) {
884                                                                                 // Is there a Long constructor?
885                                                                                 for (Constructor c : constructors) {
886                                                                                         Class[] cParms = c
887                                                                                                         .getParameterTypes();
888                                                                                         if ((cParms != null)
889                                                                                                         && (cParms.length == 1)) {
890                                                                                                 if (Long.class
891                                                                                                                 .isAssignableFrom(cParms[0])) {
892                                                                                                         constObj = c
893                                                                                                                         .newInstance(Long
894                                                                                                                                         .parseLong(paramValue));
895                                                                                                 }
896                                                                                         }
897                                                                                 }
898
899                                                                         }
900
901                                                                         if (constObj != null) {
902                                                                                 try {
903                                                                                         //LOG.debug("Calling "
904                                                                                         //              + toObj.getClass()
905                                                                                         //                              .getName() + "."
906                                                                                         //              + m.getName() + "("
907                                                                                         //              + constObj + ")");
908                                                                                         m.invoke(toObj, constObj);
909                                                                                         foundValue = true;
910                                                                                 } catch (Exception e2) {
911                                                                                         LOG.error(
912                                                                                                         "Caught exception trying to call "
913                                                                                                                         + m.getName(), e2);
914                                                                                 }
915                                                                         } else {
916                                                                                 try {
917                                                                                         boolean isAccessible = m
918                                                                                                         .isAccessible();
919                                                                                         if (!isAccessible) {
920                                                                                                 m.setAccessible(true);
921                                                                                         }
922                                                                                         //LOG.debug("Calling "
923                                                                                         //              + toObj.getClass()
924                                                                                         //                              .getName() + "."
925                                                                                         //              + m.getName() + "("
926                                                                                         //              + paramValue + ")");
927                                                                                         m.invoke(toObj, paramValue);
928                                                                                         if (!isAccessible) {
929                                                                                                 m.setAccessible(isAccessible);
930                                                                                         }
931                                                                                         foundValue = true;
932
933                                                                                 } catch (Exception e) {
934                                                                                         LOG.error(
935                                                                                                         "Caught exception trying to convert value returned by"
936                                                                                                                         + toClass.getName()
937                                                                                                                         + "."
938                                                                                                                         + m.getName()
939                                                                                                                         + "() to Properties entry",
940                                                                                                         e);
941                                                                                 }
942                                                                         }
943                                                                 } catch (Exception e1) {
944                                                                         LOG.warn(
945                                                                                         "Could not find a suitable constructor for "
946                                                                                                         + paramClass.getName(), e1);
947                                                                 }
948
949                                                                 /*
950                                                                  * try { boolean isAccessible =
951                                                                  * m.isAccessible(); if (!isAccessible) {
952                                                                  * m.setAccessible(true); } LOG.debug("Calling "
953                                                                  * + toObj.getClass().getName() + "." +
954                                                                  * m.getName() + "(" + paramValue + ")");
955                                                                  * m.invoke(toObj, paramValue); if
956                                                                  * (!isAccessible) {
957                                                                  * m.setAccessible(isAccessible); } foundValue =
958                                                                  * true;
959                                                                  * 
960                                                                  * } catch (Exception e) { LOG.error(
961                                                                  * "Caught exception trying to convert value returned by"
962                                                                  * + toClass.getName() + "." + m.getName() +
963                                                                  * "() to Properties entry", e); }
964                                                                  */
965                                                         }
966                                                 }
967                                         }
968                                 } // End of section handling "setter" method
969                         } // End of loop through Methods
970                 } // End of section handling yang-generated class
971
972                 if (foundValue) {
973                         return (toObj);
974                 } else {
975                         return (null);
976                 }
977         }
978
979         public static Properties getProperties(PrintStream pstr, String pfx,
980                         Class toClass) {
981                 boolean foundValue = false;
982
983                 //LOG.debug("Analyzing " + toClass.getName() + " class : pfx " + pfx);
984
985                 if (isYangGenerated(toClass)
986                                 && (!Identifier.class.isAssignableFrom(toClass))) {
987                         // Class is yang generated.
988                         //LOG.debug(toClass.getName() + " is a Yang-generated class");
989
990                         if (toClass.getName().endsWith("Key")) {
991                                 if (Identifier.class.isAssignableFrom(toClass)) {
992                                         //LOG.debug(Identifier.class.getName()
993                                         //              + " is assignable from " + toClass.getName());
994                                 } else {
995
996                                         //LOG.debug(Identifier.class.getName()
997                                         //              + " is NOT assignable from " + toClass.getName());
998                                 }
999                         }
1000
1001                         String propNamePfx = null;
1002                         if (pfx.endsWith("]")) {
1003                                 propNamePfx = pfx;
1004                         }else if(pfx.indexOf(".CLASS_FOUND") != -1){
1005                                 pfx = pfx.replace(".CLASS_FOUND","");   
1006                                 propNamePfx = pfx + "."
1007                                         + toLowerHyphen(toClass.getSimpleName());
1008                         } else {
1009
1010                                 if ((pfx != null) && (pfx.length() > 0)) {
1011                                         propNamePfx = pfx + "."
1012                                                         + toLowerHyphen(toClass.getSimpleName());
1013                                 } else {
1014                                         propNamePfx = toLowerHyphen(toClass.getSimpleName());
1015                                 }
1016
1017                                 if (propNamePfx.endsWith("-builder")) {
1018                                         propNamePfx = propNamePfx.substring(0, propNamePfx.length()
1019                                                         - "-builder".length());
1020                                 }
1021
1022                                 if (propNamePfx.endsWith("-impl")) {
1023                                         propNamePfx = propNamePfx.substring(0, propNamePfx.length()
1024                                                         - "-impl".length());
1025                                 }
1026                         }
1027
1028                         // Iterate through getter methods to figure out values we need to
1029                         // set
1030
1031                         for (Method m : toClass.getMethods()) {
1032                                 //LOG.debug("Is " + m.getName() + " method a getter?");
1033                                 if (isGetter(m)) {
1034                                 //      LOG.debug(m.getName() + " is a getter");
1035                                         Class returnClass = m.getReturnType();
1036
1037                                         String fieldName = toLowerHyphen(m.getName().substring(3));
1038                                         if(m != null && m.getName().matches("^is[A-Z].*")){
1039                                                 fieldName = toLowerHyphen(m.getName().substring(2));
1040                                         }
1041                                         fieldName = fieldName.substring(0, 1).toLowerCase()
1042                                                         + fieldName.substring(1);
1043
1044                                         String propName = propNamePfx + "." + fieldName;
1045                                         //System.out.println("****" + propName);
1046
1047                                         // Is the return type a yang generated class?
1048                                         if (isYangGenerated(returnClass)) {
1049                                                 // Is it an enum?
1050                                                 if (returnClass.isEnum()) {
1051
1052                                                         //LOG.debug(m.getName() + " is an Enum");
1053                                                         //pstr.print("\n" + propName);
1054                                                         //pstr.print("\n" + propName + ":Enum:" + Arrays.asList(returnClass.getEnumConstants()) + "\n");
1055                                                         pstr.print("\"" + propName + ":Enum:" + Arrays.asList(returnClass.getEnumConstants()) + "\",");
1056                                                         prop.setProperty(propName,"");
1057                                                         propList.add(propName);
1058
1059                                                 } else {
1060                                                         
1061                                                         String simpleName = returnClass.getSimpleName();
1062                                                         //System.out.println("simpleName:" + simpleName);
1063                                                         
1064                                                         if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName) || "Ipv4Prefix".equals(simpleName) || "Ipv6Prefix".equals(simpleName) || "IpPrefix".equals(simpleName)) {
1065                                                                 //LOG.debug(m.getName()+" is an "+simpleName);
1066                                                                 //pstr.print("\n" + propName);
1067                                                                 //pstr.print("\n" + propName + ":" + simpleName + "\n");
1068                                                                 pstr.print("\"" + propName + ":" + simpleName + "\",");
1069                                                                 prop.setProperty(propName,"");
1070                                                                 propList.add(propName);
1071                                                         } else {
1072                                                                 boolean isString = false;
1073                                                                 boolean isNumber = false;
1074                                                                 boolean isBoolean = false;
1075                                                                 boolean isIdentifier = false;
1076                                                                 //System.out.println("simpleName:" + simpleName);
1077                                                                 //System.out.println("propName:" + propName);
1078                                                                 for(Method mthd : returnClass.getMethods()){
1079                                                                         String methodName = mthd.getName();
1080                                                                         //System.out.println("methodName:" + methodName);
1081                                                                         if(methodName.equals("getValue")){
1082                                                                                 Class retType = mthd.getReturnType();
1083                                                                                 //System.out.println("retType:" + retType);
1084                                                                                 isString = String.class.isAssignableFrom(retType);
1085                                                                                 isNumber = Number.class.isAssignableFrom(retType);
1086                                                                                 isBoolean = Boolean.class.isAssignableFrom(retType);
1087                                                                                 isIdentifier = Identifier.class.isAssignableFrom(retType);
1088                                                                                 //System.out.println("isString:" + isString);
1089                                                                                 //System.out.println("isNumber:" + isNumber);
1090                                                                                 //System.out.println("isNumber:" + isNumber);
1091                                                                                 break;
1092                                                                         }
1093                                                                 }
1094
1095                                                                 if(isString){
1096                                                                         pstr.print("\"" + propName + ":String\",");
1097                                                                         prop.setProperty(propName,"");
1098                                                                         propList.add(propName);
1099                                                                 }else if(isNumber){
1100                                                                         pstr.print("\"" + propName + ":Number\",");
1101                                                                         prop.setProperty(propName,"");
1102                                                                         propList.add(propName);
1103                                                                 }else if(isBoolean){
1104                                                                         pstr.print("\"" + propName + ":Boolean\",");
1105                                                                         prop.setProperty(propName,"");
1106                                                                         propList.add(propName);
1107                                                                 }else if(isIdentifier){
1108                                                                         //System.out.println("isIdentifier");
1109                                                                         //isIdentifer so skipping 
1110                                                                         continue;
1111                                                                 }else{
1112                                                                 /*
1113                                                                 System.out.println("fieldName:" + fieldName);
1114                                                                 System.out.println("simpleName:" + simpleName);
1115                                                                 System.out.println("returnClass:" + returnClass);
1116                                                                 System.out.println("pstr:" + pstr);
1117                                                                 System.out.println("propNamePfx:" + propNamePfx);
1118                                                                 */
1119                                                                 getProperties(pstr, propNamePfx + ".CLASS_FOUND", returnClass);
1120                                                                 }
1121                                                         }
1122
1123                                                 }
1124                                         } else {
1125
1126                                                 // Setter's argument is not a yang-generated class. See
1127                                                 // if it is a List.
1128
1129                                                 if (List.class.isAssignableFrom(returnClass)) {
1130
1131                                                         //LOG.debug("Parameter class "
1132                                                         //              + returnClass.getName() + " is a List");
1133
1134                                                         // Figure out what type of args are in List and pass
1135                                                         // that to toList().
1136
1137                                                         Type returnType = m.getGenericReturnType();
1138                                                         Type elementType = ((ParameterizedType) returnType)
1139                                                                         .getActualTypeArguments()[0];
1140                                                         Class elementClass = (Class) elementType;
1141                                                         //LOG.debug("Calling printPropertyList on list type ("
1142                                                                         //+ elementClass.getName()
1143                                                                 //      + "), pfx is ("
1144                                                                 //      + pfx
1145                                                                 //      + "), toClass is ("
1146                                                                 //      + toClass.getName() + ")");
1147                                                         //System.out.println("List propNamePfx:" + propNamePfx+ "." + toLowerHyphen(elementClass.getSimpleName()) + "[]");
1148                                                         if(String.class.isAssignableFrom(elementClass)){
1149                                                                 pstr.print("\"" + propName + ":[String,String,...]\",");
1150                                                                 prop.setProperty(propName,"");
1151                                                                 propList.add(propName);
1152                                                         }else if(Number.class.isAssignableFrom(elementClass)){
1153                                                                 pstr.print("\"" + propName + ":[Number,Number,...]\",");
1154                                                                 prop.setProperty(propName,"");
1155                                                                 propList.add(propName);
1156                                                         }else if(Boolean.class.isAssignableFrom(elementClass)){
1157                                                                 pstr.print("\"" + propName + ":[Boolean,Boolean,...]\",");
1158                                                                 prop.setProperty(propName,"");
1159                                                                 propList.add(propName);
1160                                                         }else if(Identifier.class.isAssignableFrom(elementClass)){
1161                                                                 continue;
1162                                                         }else{
1163                                                                 getProperties(
1164                                                                         pstr,
1165                                                                         propNamePfx
1166                                                                                         + "."
1167                                                                                         + toLowerHyphen(elementClass
1168                                                                                                         .getSimpleName()) + "[]",
1169                                                                         elementClass);
1170                                                         }
1171
1172                                                 } else if (!returnClass.equals(Class.class)) {
1173
1174                                                         // Setter expects something that is not a List and
1175                                                         // not yang-generated. Just pass the parameter value
1176
1177                                                         //LOG.debug("Parameter class "
1178                                                         //              + returnClass.getName()
1179                                                         //              + " is not a yang-generated class or a List");
1180
1181                                                         //pstr.print("\n" + propName);
1182                                                         String className=returnClass.getName();
1183                                                         int nClassNameIndex = className.lastIndexOf('.');
1184                                                         String nClassName = className;
1185                                                         if(nClassNameIndex != -1){
1186                                                                 nClassName=className.substring(nClassNameIndex+1);
1187                                                         }
1188                                                         boolean isString = String.class.isAssignableFrom(returnClass);
1189                                                         boolean isNumber = Number.class.isAssignableFrom(returnClass);
1190                                                         boolean isBoolean = Boolean.class.isAssignableFrom(returnClass);
1191                                                         //pstr.print("\n" + propName +":" + nClassName +"\n");
1192                                                         boolean isIdentifier = Identifier.class.isAssignableFrom(returnClass);
1193                                                         if(!isIdentifier && !nClassName.equals("[C")){
1194                                                                 if(isNumber){
1195                                                                         pstr.print("\"" + propName +":Number\",");
1196                                                                 }else if(isBoolean){
1197                                                                         pstr.print("\"" + propName +":Boolean\",");
1198                                                                 }else{
1199                                                                         if(nClassName.equals("[B")){
1200                                                                                 pstr.print("\"" + propName +":Binary\",");
1201                                                                         }else{
1202                                                                                 pstr.print("\"" + propName +":" + nClassName +"\",");
1203                                                                         }
1204                                                                 }
1205                                                                 prop.setProperty(propName,"");
1206                                                                 propList.add(propName);
1207                                                         }
1208
1209                                                 }
1210                                         }
1211                                 } // End of section handling "setter" method
1212                         } // End of loop through Methods
1213                 } // End of section handling yang-generated class
1214
1215                 return prop;
1216         }
1217
1218         public static boolean isYangGenerated(Class c) {
1219                 if (c == null) {
1220                         return (false);
1221                 } else {
1222                         //System.out.println(c.getName());
1223                         return (c.getName().startsWith("org.opendaylight.yang.gen."));
1224                 }
1225         }
1226         
1227         public static boolean isIpv4Address(Class c) {
1228                 
1229                 if (c == null ) {
1230                         return (false);
1231                 }
1232                 String simpleName = c.getSimpleName();
1233                 return ("Ipv4Address".equals(simpleName)) ;
1234         }
1235         
1236         public static boolean isIpv6Address(Class c) {
1237                 
1238                 if (c == null ) {
1239                         return (false);
1240                 } 
1241                 String simpleName = c.getSimpleName();
1242                 return ("Ipv6Address".equals(simpleName)) ;
1243         }
1244         public static boolean isIpv4Prefix(Class c) {
1245                 
1246                 if (c == null ) {
1247                         return (false);
1248                 }
1249                 String simpleName = c.getSimpleName();
1250                 //System.out.println("simpleName:" + simpleName);
1251                 return ("Ipv4Prefix".equals(simpleName)) ;
1252         }
1253
1254         public static boolean isIpv6Prefix(Class c) {
1255                 
1256                 if (c == null ) {
1257                         return (false);
1258                 }
1259                 String simpleName = c.getSimpleName();
1260                 //System.out.println("simpleName:" + simpleName);
1261                 return ("Ipv6Prefix".equals(simpleName)) ;
1262         }
1263
1264         public static String toLowerHyphen(String inStr) {
1265                 if (inStr == null) {
1266                         return (null);
1267                 }
1268
1269                 String str = inStr.substring(0, 1).toLowerCase();
1270                 if (inStr.length() > 1) {
1271                         str = str + inStr.substring(1);
1272                 }
1273
1274                 String regex = "(([a-z0-9])([A-Z]))";
1275                 String replacement = "$2-$3";
1276
1277                 String retval = str.replaceAll(regex, replacement).toLowerCase();
1278
1279                 //LOG.debug("Converting " + inStr + " => " + str + " => " + retval);
1280                 return (retval);
1281         }
1282
1283         public static String toUpperCamelCase(String inStr) {
1284                 if (inStr == null) {
1285                         return (null);
1286                 }
1287
1288                 String[] terms = inStr.split("-");
1289                 StringBuffer sbuff = new StringBuffer();
1290                 // Check if string begins with a digit
1291                 if (Character.isDigit(inStr.charAt(0))) {
1292                         sbuff.append('_');
1293                 }
1294                 for (String term : terms) {
1295                         sbuff.append(term.substring(0, 1).toUpperCase());
1296                         if (term.length() > 1) {
1297                                 sbuff.append(term.substring(1));
1298                         }
1299                 }
1300                 return (sbuff.toString());
1301
1302         }
1303
1304         public static boolean isGetter(Method m) {
1305                 //System.out.println(m);
1306                 if (m == null) {
1307                         return (false);
1308                 }
1309
1310                 if (Modifier.isPublic(m.getModifiers())
1311                                 && (m.getParameterTypes().length == 0)) {
1312                         if ((m.getName().matches("^is[A-Z].*") || m.getName().matches("^get[A-Z].*"))
1313                                         && m.getReturnType().equals(Boolean.class)) {
1314                                 return (true);
1315                         }
1316                         if (m.getName().matches("^get[A-Z].*")
1317                                         && !m.getReturnType().equals(void.class)) {
1318                                 return (true);
1319                         }
1320
1321                 }
1322
1323                 return (false);
1324         }
1325
1326         public static boolean isSetter(Method m) {
1327                 if (m == null) {
1328                         return (false);
1329                 }
1330
1331                 if (Modifier.isPublic(m.getModifiers())
1332                                 && (m.getParameterTypes().length == 1)) {
1333                         if (m.getName().matches("^set[A-Z].*")) {
1334                                 Class[] paramTypes = m.getParameterTypes();
1335                                 if (paramTypes[0].isAssignableFrom(Identifier.class)
1336                                                 || Identifier.class.isAssignableFrom(paramTypes[0])) {
1337                                         return (false);
1338                                 } else {
1339                                         return (true);
1340                                 }
1341                         }
1342
1343                 }
1344
1345                 return (false);
1346         }
1347
1348         public static void main(String[] args){
1349                 
1350                try(PrintStream ps = new PrintStream(new FileOutputStream(FileDescriptor.out))){
1351                         PrintYangToProp printYangToProp = new PrintYangToProp();
1352                         String className = args[0];
1353                         //ClassLoader classLoader = PrintYangToProp.class.getClassLoader();
1354                         //Class aClass = classLoader.loadClass(className);
1355                         Class cl = Class.forName(className);
1356                         //printPropertyList(ps,"",cl);
1357                         //JsonObject jsonObj = Json.createObjectBuilder().build();
1358                         Properties p = getProperties(ps,"",cl); 
1359                         //System.out.println(p);
1360
1361                 }catch(Exception e){
1362                         e.printStackTrace();
1363                 }
1364         }
1365
1366
1367 }